Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp848260lqm; Wed, 1 May 2024 18:59:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXnbySVbXISrLPT3nvjI0rS+tbX9OFHLSlBpwC9XeeauCn02ufiUs7NqFFGowr6n4TGllSZ7ff/JBVnoXPoUb2KjJd9HchCAVdneCv5LQ== X-Google-Smtp-Source: AGHT+IGXosB7YrEr1LO/QvblcJY2TpNf+bemd9H5JWav05iGL9UmFzDK7lC5IMl2pQdRywnB+nL5 X-Received: by 2002:a05:6808:4196:b0:3c8:654f:e953 with SMTP id dj22-20020a056808419600b003c8654fe953mr772403oib.53.1714615170989; Wed, 01 May 2024 18:59:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714615170; cv=pass; d=google.com; s=arc-20160816; b=xjaPiX2Z+SnsYDRIeKtrMwDDl0aJh28HsHZwO5rGmCvi1KPpLAzDdAH6IYTz7hYPE9 8+epYjRpV/19JX86FZhAVrn+lJn+akQ9lsvwi5dvE1gc2bgqMYgx1UmqQT5YnidG99ZX 8y7iowd0FHkxjw6+FAFVp0UArPCwqPJOh7blS+2vO/DfPmhTv19ibiIxEpafnV5SL54i Nx8zxFcixjhb9lPzcv1b40yrq5eyFm6ThFcJhtnJIZWv29bF9xupgjhQXNRdqY45x4Ff V0TtPYbH9a6UT5a57ez+XNa7culSTzSfru/bEH001CjKl85VjLbBI1XRnEJDIGPABWla L8lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=3ive2AfPIQkDY1GsuetqyUHhjY3A5Y320G63LPrXKpg=; fh=GZpB+23hS60jmu+hKJaXmUS0z/LJyB8ihlMvW8pUUB4=; b=nc8Ngj3/JltLhbdp87cdZWCwOA+x54GRyIus5GhC9KdPufuNKFsWpOPVVacO6aSTxg GxqmmJaLcmkVAuwzMChLc3rnJlGzwRI5a+dZZlKOBeT5GiHmG6wggKy5m94WZYWlQuE1 97utQs+31sxi8VE52OxZoIgOXDOuBYxmrf3ir+uDM+kyc6vrvD+Jz2CXTI7rnIQeKy62 SnKg1V9udObpCj3Y+H/zPzDZH4adqKDu4dZ3PnHedcJIKSfptWPTLJ2EaIQEmIV7Nxep 031uP2o8O03M/xAv2YrZjbWCYjEfdRCESiAyhZlSnFZ1et2W0/wbr9EQDvJOG6pwppYz 8mNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6vwFJH7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-165907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dv12-20020ad44eec000000b006a0cb1183basi8906075qvb.165.2024.05.01.18.59.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 18:59:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6vwFJH7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-165907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B21821C21602 for ; Thu, 2 May 2024 01:59:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B9DA171BB; Thu, 2 May 2024 01:59:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K6vwFJH7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D995ED299; Thu, 2 May 2024 01:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714615162; cv=none; b=XRWBMV3JIgMUZeWN5i7HmtDuiHxzSx16QNYjszRZLyjdp4yITD+5X0y1IMhoasjWgdMT757Q41pwWyTEjpTN79iIXHQRTT6+VGhNY0TVeRmApTo8GKPn8K0GzLbcocR2jgNq+/RS2OoICRwkH8qun8R+6/IWKhG5rtx7+eiLdYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714615162; c=relaxed/simple; bh=zKP4feh47Akq95l05ylgljUzunXEWN+72fMuFIKrAxs=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=JJwFfyH5XiYzGbeHAm83J+c5c24lymVKmCMJ3txBfFcmb/O2jkosZgkRkUesXSakxMVloiMD49QEVcd+F16O+W2ng6GnuvdKzQgXqm+EuijCGSsLr29rODtd6JMk8Js/BerEgnSPTuYMHGK4T4lDGj0xqHWkdb8DvF5rW2boFyI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=K6vwFJH7; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714615161; x=1746151161; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=zKP4feh47Akq95l05ylgljUzunXEWN+72fMuFIKrAxs=; b=K6vwFJH7V8TdKS+6SQQlDkwHBmlVlGdMwRwycy0RJl1dYRBZVK78jnJT Z9/jLvyzRuJ27F8/OEjih9AgaWym0hx7ROUHR2atvZC8mWWnuQTMJy2Dw E2cSUav4apcpOfRfgBiYpTqbpnb+ekpIysj2mVl5ewKmGc7BwVXQL+9OK pEVCF/Bka48wodTIzD2CpfdbM5aihASfTEaVQoUR0dpNSj9GjaFppn891 VEN6sdknWCLpOJrJ+zRHcOnRfTNf1sCIslctclEGjZudWlCD/16IjpYG3 5CJA1Rz9MeFZ3Gs6EXACmSqcx9mMIaE6WbPiM6iP6qepoBluxQIDBdkik A==; X-CSE-ConnectionGUID: +aznVMTiRoOz0Q2i3GNS0g== X-CSE-MsgGUID: BWr2Hv5XTTeryibfOARyYA== X-IronPort-AV: E=McAfee;i="6600,9927,11061"; a="10536756" X-IronPort-AV: E=Sophos;i="6.07,247,1708416000"; d="scan'208";a="10536756" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2024 18:59:20 -0700 X-CSE-ConnectionGUID: 5TEYAUJHQm6qKX56L2o3ug== X-CSE-MsgGUID: BnZJQJRhTU2OMxt832m4uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,247,1708416000"; d="scan'208";a="31782767" Received: from unknown (HELO [10.239.159.127]) ([10.239.159.127]) by orviesa004.jf.intel.com with ESMTP; 01 May 2024 18:59:15 -0700 Message-ID: Date: Thu, 2 May 2024 09:57:44 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Palmer Dabbelt , Albert Ou , Anup Patel , Sunil V L , Nick Kossifidis , Sebastien Boeuf , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux@rivosinc.com Subject: Re: [PATCH v3 5/7] iommu/riscv: Device directory management. To: Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley References: <104358de-ea86-4e25-8942-ba285d6f317b@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <104358de-ea86-4e25-8942-ba285d6f317b@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/2/24 9:38 AM, Baolu Lu wrote: > On 5/1/24 4:01 AM, Tomasz Jeznach wrote: >> @@ -128,6 +489,7 @@ void riscv_iommu_remove(struct riscv_iommu_device >> *iommu) >>   { >>       iommu_device_unregister(&iommu->iommu); >>       iommu_device_sysfs_remove(&iommu->iommu); >> +    riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_MODE_OFF); >>   } >>   int riscv_iommu_init(struct riscv_iommu_device *iommu) >> @@ -138,12 +500,13 @@ int riscv_iommu_init(struct riscv_iommu_device >> *iommu) >>       if (rc) >>           return dev_err_probe(iommu->dev, rc, "unexpected device >> state\n"); >> -    /* >> -     * Placeholder for a complete IOMMU device initialization. >> -     * For now, only bare minimum: enable global identity mapping >> mode and register sysfs. >> -     */ >> -    riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP, >> -               FIELD_PREP(RISCV_IOMMU_DDTP_MODE, >> RISCV_IOMMU_DDTP_MODE_BARE)); >> +    rc = riscv_iommu_iodir_alloc(iommu); >> +    if (rc) >> +        goto err_init; >> + >> +    rc = riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_MODE_MAX); >> +    if (rc) >> +        goto err_init; >>       rc = iommu_device_sysfs_add(&iommu->iommu, NULL, NULL, >> "riscv-iommu@%s", >>                       dev_name(iommu->dev)); > > The device directory root page might be allocated in > riscv_iommu_iodir_alloc(), > > +    if (!iommu->ddt_root) { > +        iommu->ddt_root = riscv_iommu_get_pages(iommu, 0); > +        iommu->ddt_phys = __pa(iommu->ddt_root); > +    } > > But I didn't find any place to free it in the error paths. Did I > overlook anything? I found the answer by myself. devres_alloc() is used so the page memory resources are managed by the driver core automatically. Please ignore the above comment. Not sure about the pages for paging domain. If all pages release is deferred, it may cause big memory consumption. We have a trade-off here. On one hand, this might speed up the domain mapping since all pages might be preallocated; on the other hand, it will cost more memory. Best regards, baolu