From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (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 E05131E1A3D for ; Tue, 7 Jan 2025 19:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736277262; cv=none; b=m94O6DXvRamrFLAKODMCrVcyUP3wERG3UpQciBorag/pURLiLtPn30BIbIptC5rs3m6+Kn5ofCkjw6vrvzT4Uvi+F/W9aALAEqSS2KSIc9SmV55t528TcCUaDcWA5fbqj2dQiMtM62WRoJsGnZV8HkIv6M3IBesuqWsB2irmFIk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736277262; c=relaxed/simple; bh=JWWSlr546QF/Ojod4A+nTboyQKMLYGiAA95RDQAX/To=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LO2gNHLTBzX5hrXw++kp6YdtwqnDdoPdVm07/q1mY1AEj/DURUfE5FK7iGBOXg39hika05w4B//V2uXSCwg5ovb6yyjbtQRo2Uyl7ElS9IStYIFku+eJlUCzuSdCIFa72JP97+I4g/VfkAqLDdEqR5wJMGF51y5B3XqhbTjelfw= 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=NTHxSahl; arc=none smtp.client-ip=209.85.160.181 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="NTHxSahl" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-46772a0f85bso132852401cf.3 for ; Tue, 07 Jan 2025 11:14:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736277257; x=1736882057; 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=SEN5Mj96bM8YcY4Gv0++Fg9PbmwUSh4czT7h1uET0WU=; b=NTHxSahlhCRGLJN5O9pfWL24JdDa8/wvjAabMi1aPb74A56vneX6u7dGqp239xbJCZ i6GM7+NTJO69kW233jD9vM3I9RBQbITD7E/omrFXrjlte0BV2s6TIm1GvCQMBgmEfnZf CBNkDMgwSdDrgqFslu45+TxlYUZi2vVNYmw9g7H2RPF9Bq+A7A/JiAnv2UZNDQ9gJ5MX 9kCPBst8MCywOK+817W8X3OxBflMLnUwsUjoz8zlrmN0zfJ8a43Rz54iUB0vA3wwfBDo MBarSv+yY6Pz1ruCzITVuPKJCaRAsuqWtc+/C09n33UmVKj3S4UX8bV4MqPlAT6D+EHT bOoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736277257; x=1736882057; 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=SEN5Mj96bM8YcY4Gv0++Fg9PbmwUSh4czT7h1uET0WU=; b=nWZF9HXQfff+4Yjcz5KNmhM7aEXQNNaB/OVO3OKZ8WXs2AHJTuCsC5EgdwAKlxXbgY 4QVB1ZW5fg59LyhtlHUlzX9+TZ5rE+lKS2afdeaFA0dS/Lgh1WZtyAxa2fOHPHhrIIxh u8erAaEupel0VO9IpH52Eulr/pKmodlODmFqb2anB8ixqNHlq1ua4dlSQN3EkKVdkgiz wCAZOkSSalF9NcMefmDUJc8RrfJ0jyzMZdi+G+3IZBj8OAT1q9sJJP1YVAn9XgOMPk7U Miip99nW9mGBhrfCMEh8T31X1RoEcYVH0XXW0j7hGaMufYbnyKxaUsq+fKNO4GN8N8Hy aVFw== X-Forwarded-Encrypted: i=1; AJvYcCUZvaP5aWR/DhIvX65NAJuO9jOpf/YaAsvFi7e4tk2rSNHFOmioUxy9Iz77J8mhu+nsR6PhYXPNWBnfs7c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8lij8OkWWPTPnP2+RaJBm/1R4Zzw32xPERE+NpCYMfklVl5ku tttdPcALAAmLI5SsWIM0nVOF9ncFlyJslDvRga9MKiYgQQzRkIqONhv8ASF0Vj0= X-Gm-Gg: ASbGncvQBjLwmAq0PWCXnvb2DnBNjC/obuAqAUSqFQURz5do7TSpmkjSBJAhfEwk51M hppVmbMAl0y4vVknURQj93AYeU1hxYeYBKmHb2qjRma1Odwt+YMFXUxiWAOtW88pdK/tej8zlik WuIt/mOb++qYnUVU6zoJ451Ha36QNvJCbYcxSifueK5uKvjqs6E2ygasUkSWQwj+eY2UXvQra/z RceMDH5h3eBvkb60QLgBWnco/97sbuLTI87ob3fv4e1s1B3h7QN6u1Gk7mjF+znAy9MViilu+3X y+OmOk0XYCTgpS/Xjnx528NtRTZQCkAO+GQ4MgY= X-Google-Smtp-Source: AGHT+IE+UWZ8eXb4MJFaAPhyQHqwNX/ssf57HkKvpRv61oVHdww4YvDlPRDvhWCtSKcT+itrEjTygw== X-Received: by 2002:a05:6214:1316:b0:6d8:e634:204d with SMTP id 6a1803df08f44-6df9b2b29d3mr2968686d6.38.1736277256823; Tue, 07 Jan 2025 11:14:16 -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 6a1803df08f44-6dd181372easm184473886d6.63.2025.01.07.11.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 11:14:16 -0800 (PST) Date: Tue, 7 Jan 2025 14:14:14 -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 15/29] cxl/region: Use an endpoint's SPA range to find a region Message-ID: References: <20250107141015.3367194-1-rrichter@amd.com> <20250107141015.3367194-16-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-16-rrichter@amd.com> On Tue, Jan 07, 2025 at 03:10:01PM +0100, Robert Richter wrote: > To find the correct region and root port of an endpoint of a system > needing address translation, the endpoint's HPA range must be > translated to each of the parent port address ranges up to the root > decoder. > > Calculate the SPA range using the newly introduced callback function > port->to_hpa() that translates the decoder's HPA range to its parent > port's HPA range of the next outer memory domain. Introduce the helper > function cxl_port_calc_hpa() for this to calculate address ranges > using the low-level port->to_hpa() callbacks. Determine the root port > SPA range by iterating all the ports up to the root. Store the > endpoint's SPA range and use it to find the endpoint's region. > Some comments/questions inline. > Signed-off-by: Robert Richter > --- > drivers/cxl/core/region.c | 85 ++++++++++++++++++++++++++++++++------- > drivers/cxl/cxl.h | 1 + > 2 files changed, 71 insertions(+), 15 deletions(-) ... snip ... > + while (1) { > + parent = parent_port_of(iter); > + I'm always suspicious of unbounded while loops. Should this simply be while(iter) { ... } Instead? Given the rest of the function, I don't think this matters, but it's at least a bit clearer. > + if (is_cxl_endpoint(iter)) > + cxld = &cxled->cxld; > + else if (!parent || parent->to_hpa) > + cxld = cxl_port_find_switch_decoder(iter, &hpa); > + > + if (!cxld) { > + dev_err(cxlmd->dev.parent, > + "%s:%s no CXL window for range %#llx:%#llx\n", > + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), > + hpa.start, hpa.end); > + return -ENXIO; > + } I also think we should be able to move this check out of the loop on various break conditions (iter==NULL, cxld not found, etc). > + > + /* No parent means the root port was found. */ > + if (!parent) > + break; > + > + /* Translate HPA to the next upper memory domain. */ > + if (cxl_port_calc_hpa(parent, cxld, &hpa)) > + return -ENXIO; > + > + iter = parent; > } > > + dev_dbg(cxld->dev.parent, > + "%s:%s: range:%#llx-%#llx\n", > + dev_name(&cxled->cxld.dev), dev_name(&cxld->dev), > + hpa.start, hpa.end); > + > cxled->cxlrd = to_cxl_root_decoder(&cxld->dev); > + cxled->spa_range = hpa; > > return 0; > } Overall good, just think we might be able to improve the readability / safety of this loop a bit. Stupid question: I presume a look in this iteration is not (generally?) possible, but if it were to happen this while loop as-is would go infinite. Is that something we should worry about it? ~Gregory