From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 907D719408C for ; Tue, 7 Jan 2025 22:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736289196; cv=none; b=txmDtVbaGH9cFyUUgvn7XAokmVfqwGR+Z19dL7pI5l2tZwOrtEPYEr4lZ6U7F/dacIIuJxEDwFgLyhj+lkv/+YtHzouxiywiLaVFvEEHW67XIC0mjTnNUwvAOepDqorrfn/2MRb411NuUiWQcQWOCYBsAWtryHRoUnW2bA1PMZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736289196; c=relaxed/simple; bh=tNwgxqOT/vI/GIvjoscnIuOyBkzLYkjGKwTFuBByznA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GwPqe5Q4U/tJFdXt5LH5ldGq9WDcH3CLmWylGLQWGVvqFVb6dQyAnFYyccujxck6yrisRn5ki7/gcgU4edN5FBp814vJz0nzm7rW8pfPFyoxabHGnTu+oTsZmFb/X0k4v78VXSSvcQbK5AFRh5uE3gtm6NO8kZoiig8Tk5ogKbw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=CNUoObEj; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="CNUoObEj" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b98a2e3b3eso795818685a.2 for ; Tue, 07 Jan 2025 14:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736289192; x=1736893992; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qpX6JiZ5ixPvDUx6ndbdQvSLHYQ9YjrroJ3HRy4IFyI=; b=CNUoObEjso55Fh6dCeqhr/ZA2Ojq6dUwbSBYCY7dz5MNlfkDsjw9jK+pxEVatkP840 WzOIXbhakXurZ9wyHBuEXrRRlMbkc/noWWA5uDS5vNivvQvFXR54ytGGSK5UF8YWPR82 FgRVRpEKt/kiZ92CKJ/+KP2evZlHJAeBVcj/PMVicwAAqymUPkHqQWKQP7f1VnTwHipl iTfvS1EIpk/asI2nInOb80e4vTgMWprh4/19zlWNokNe/rAeA4/pfsteQtaUD/OZFJMC v1jUxdf7Iif6dJ/h1cD28g8x3mQd35tgd0voDPUL7kHAq1PbP46+sB0JPnvkYyKrpCu6 Nxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736289192; x=1736893992; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qpX6JiZ5ixPvDUx6ndbdQvSLHYQ9YjrroJ3HRy4IFyI=; b=IOebg0JChUGhh56xThABB8V5A1JSIIF50jaG+T+yapcPsXpFPBRCfipNZvqb3JZY5x czC7IGn4QC6CmhPEFA/D/nEM9IKVKHEkPPYS0CwxLzsiP2bXaDxtRb44bPbKvigI7wYn gUkXEGWsbbnMIaw1Hm4f3Eg+yjOdnv+VtP0zAKmCjqWzOrh8+UL60br//ewtcy1alSVL c6/CtdwsqTYRfRgFvxBi53l0h/wmyQS83NzjeLTiBGJCjdeHzbLMb3WIbp6CV4VFw12j hOXxQ6eKNOqcdIuqVZ/TtJIep4ofqQKZc0e90xdjAwWFmpHx8tIwmhY6npDQETnA57N3 pEMQ== X-Forwarded-Encrypted: i=1; AJvYcCV+CL5RfO5XrQqhV0dKyzbgDj+yef9JgWEa+i+EI82yWTfwVt5etcSEpaGOmffyYm5YH+OezpqIdidQvrU=@vger.kernel.org X-Gm-Message-State: AOJu0YxqNsPpH8gIk5pxQGAptnsGKO+m+aSWlwZi1DXhlADFJK8pG1IS +6209EK4LQCf8mRov39eT/Khme9g9QpehWBQZTVIi2JdEm0aekEsHUjhqSgf/mE= X-Gm-Gg: ASbGncsA0mXTgmOQTe80rTLZSMVnGiD5/5gyAdgSa+jW+DMtaIurMUDDaih5ZPa5nGe Pp58l/pHfWi10PyYcDSH81Ak6CK0riGqjfupX7U3BFBl2coFkqyYjDOppL6A/UKCY3fY6aym+Cn izeDVsFX/VZ/t8avihp7+UM+YPPCxfrvXtjr82g3op8YuRD9Ltsq47ZSJlRlVmxCOOTRR01apTt fqpvEJqJF7rFWez85Ay8S11RBuR6St8nCYt+XgRxzPWKET99sOPwZuIteq4IKSbShWt2KI/dYfW tudv3gLf/6IzMHZYwpQmoPlTB/z+5lcqopOAvcc= X-Google-Smtp-Source: AGHT+IE84BqwkI0EuKCnUHRTjlVelOU1z5n7oTkTtGcNA90GhGXtHXKxlKsG5Wb479y22tMfhN736Q== X-Received: by 2002:a05:620a:2454:b0:7b6:db89:2e9a with SMTP id af79cd13be357-7bcd970a86dmr79800085a.22.1736289192395; Tue, 07 Jan 2025 14:33:12 -0800 (PST) Received: from gourry-fedora-PF4VCD3F (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b9ac2bbcfasm1627643885a.25.2025.01.07.14.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 14:33:11 -0800 (PST) Date: Tue, 7 Jan 2025 17:33:09 -0500 From: Gregory Price To: Robert Richter Cc: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, "Fabio M. De Francesco" , Terry Bowman Subject: Re: [PATCH v1 20/29] cxl/region: Use translated HPA ranges to find the port's decoder Message-ID: References: <20250107141015.3367194-1-rrichter@amd.com> <20250107141015.3367194-21-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250107141015.3367194-21-rrichter@amd.com> On Tue, Jan 07, 2025 at 03:10:06PM +0100, Robert Richter wrote: > This is the second step to find the port's decoder with address > translation enabled. The translated HPA range must be used to find a > decoder. The port's HPA range is determined by applying address > translation when crossing memory domains for the HPA range to each > port while traversing the topology from the endpoint up to the port. > > Introduce a function cxl_find_auto_decoder() that calculates the > port's translated address range to determine the corresponding > decoder. Use the existing helper function cxl_port_calc_hpa() for HPA > range calculation. > > Signed-off-by: Robert Richter > --- > drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++-- > 1 file changed, 61 insertions(+), 2 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 23b86de3d4e7..8d7893878362 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -876,6 +876,66 @@ static int match_auto_decoder(struct device *dev, void *data) > return 0; > } > > +static struct device * > +cxl_find_auto_decoder(struct cxl_port *port, struct cxl_endpoint_decoder *cxled, > + struct cxl_region *cxlr) > +{ > + struct cxl_port *parent, *iter = cxled_to_port(cxled); > + struct cxl_decoder *cxld = &cxled->cxld; > + struct range hpa = cxld->hpa_range; > + struct cxl_region_ref *rr; > + > + while (1) { Similar to prior patch, probably we should have while(parent) instead of while(1) and be at least a bit defensive against (extremely unlikely) loops. At the very least maybe we can express the condition more explicitly. > + parent = parent_port_of(iter); > + if (!parent) { > + dev_warn(&port->dev, > + "port not a parent of endpoint decoder %s\n", > + dev_name(&cxled->cxld.dev)); > + return NULL; > + } ... snip ...