From patchwork Wed Feb 3 23:37:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABE43C433E0 for ; Wed, 3 Feb 2021 23:39:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68FFE64F43 for ; Wed, 3 Feb 2021 23:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68FFE64F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81093.149194 (Exim 4.92) (envelope-from ) id 1l7Rjb-00060b-EQ; Wed, 03 Feb 2021 23:38:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81093.149194; Wed, 03 Feb 2021 23:38:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjb-00060S-BA; Wed, 03 Feb 2021 23:38:55 +0000 Received: by outflank-mailman (input) for mailman id 81093; Wed, 03 Feb 2021 23:38:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rja-00060K-O9 for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:38:54 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15696a5c-44f9-4663-b39b-48261f3da0e6; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N8wg9103664; Wed, 3 Feb 2021 23:37:46 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36cydm2q16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:46 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAbHS112134; Wed, 3 Feb 2021 23:37:45 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3030.oracle.com with ESMTP id 36dhd0h98t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:45 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:42 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:42 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:36 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 15696a5c-44f9-4663-b39b-48261f3da0e6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=NQGceTWcGnFSzxuNLWlAT7ftp0+qtrFa+QqxyH4luxuOx/4CbpdhaoE1Woq2H+KFeerO qHYOHjtQMoRtQcteMlRdRh0gRMZKRjAll6TtCIhagOKGAtHQK+a4RnXZyZtxYS+eWhO7 Q9zk3YuYVHCYkJer6I5mEs0RWCDyNsLtfty3ihQJahSEH+AOAXeery6C8G+lw+Wve6VO RrakFbj29sTk1eqKCA6k7frw/kNvX2KNbYKUY73dlVBQUUazqqcpjvB7x1UWhf7Oxjls +JVF9g5XDO8m4yApyiGveb+BwV1HXWmNq5cuIY7dNvj4EEXadoMkUTRMO+SamF8ipE9/ zQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dzeUWNcU9Mj4e0TYMjDEEa04Puyz6RPQSjKZYKBWfmB0YwXGpAgYd9oM8VKYP8KXENITMV8yDMjP8CYacJPwv8DWmD4pSTiPOoRhlSV0oSyx0fWkiuokgpZ+MNc10AjBFlPN3fS6+wmdDwxaSMmr3AWXeIHjleiC2b90oOD5l7lecsd4TJ9inlejRmA0LhPrJE+i4qIR9reLEtuATKI0CpBOk/U9dhS+oomHA0MkWrlzRvDNVn3m/crta3/rFfJdhqMD/lwZ4mioO+D+XS7pQ9BYpw2e4rYERQEKbrZv9QIBXA98liYSs+uPxvIe4cpX6aBF1q3jWKa57MKtPPxTeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=oRgVV+HDbkWsmdM/NCIX14g0sj7/IHgOUpcV3ziyxhzl7Gd9U6OrO+hsNKg1+9hy5LFfkCdBPZ67Gvymn2hvh0EzIWmwXrCGTGCBKlXzcua2sNyEM6w6d04IriWe5nKG8hbefsrZXYHtfl+nck4edJFi/egB74dCn39TyjYaAlQT5uc3NlHVNJY8OU7o92ZDnbztY0QqnurGr2ImA4x5GETYQOsOk+i8iBEMYO2ycotIs7s6a2T4+epsSq3dofegTAZpSmjSlWo9yQ7cTq2AF75IrKWjRMvAxpe2iczboLVN5wyQgvGjq2ox9eG5EPbYxxMX81tkmyq68p0VkxAEGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=tjvCr9fEZnS/1sygRCnSm5Q2dXA7fAn8eTEtv5NpIiQ6sP2WsjoRLTtl1Z8622ok/gg2EPDiZ56/V2lbBNjHiKgjEsauVAX7RlT/FjXK+64C4N6hsxUAM+k9NP1EKmHYkVkYTH8WDGFNWmhbaiWPaHdLUdqB+5PpwCiQeDtoIs0= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 1/6] swiotlb: define new enumerated type Date: Wed, 3 Feb 2021 15:37:04 -0800 Message-Id: <20210203233709.19819-2-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95a27da3-82a5-4fa4-cf2a-08d8c89cb345 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kyMvFO94V89ozWj18bC0Vn9q8FAfrj1y9eDdojT3KXhZ3Kb6y0lMwkIUajPU89ixDjx/OGTr/llm3guooQuOtVd+PpQ9YQUQhSfr0VFSEaouKp9j6rQxBc2TDkU3n5TWws0P+gsQ9ClTDsY9obcuVuIpjWx8canMnExyJCp5opcTw4kGqQW+2+W11CZ3GfQA/4/tYYsbBhNweERyMTssLgeMrtTCtHAaB7mU9lopLRJxj2jUoeCAvT2jIcoEdnUPcQsrrvYmOO0jFqky9d3sZhy1e0161Va50YgEy72BmrZriZB7Fl1RBIJTb13rVgOZCbpYnWmPSfKYKtobkI66O/AUHyUDOyZMTNQBR2Mv1wasGM4dt/FVklQoggzHlBFeKpjEo6m1rahep0DWs5s3iFzqE5GbyMkd7KlvzTs1OY1vFoh+bHjv8LoQzMG7W+6nLoal5vB2LR6vIuK2+agcXr4rLiYxXl+a+AkvVQmNmsI6626FXj3SqSvLeM8oEJiQZCJ4U1Q6g3nnWr4d83pSjBwkmZVCAyR8hTQR7DHXcHQnZGjwHSyBmM0W44hGWgRhS7GVj+ds0MKOwrTfTcagGfrroQKUBZjTQBUCad4qCbc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(4744005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: qeAfDC+0fc/jTywdxpwqkCaMRYdTCNWdYfhK/QFffR8uC9UvZ9YkUddjJqj8LMepJPhT0a36sLGoYCc8pE42XpdTs25YEvJgJbE+r15lAPOhZ2uG8YaqDpieYBy4aMhXnck5XH46LZbJJ5Bc6YzUGPA/RpT5PCmWbcQzB8peKv+pFSlMP+73gIpYKWEVF/EtR6TOku8PeSlGV2dRHpAnvJ67O+hahgMBD7bgCaFV694aTg4wKSujev4hlObPNbItkXf5I4GifCbVNuALJHlzJ8DOx3jIyR3vPyw0wng4LXc++9ix1gN2MitGR30SK1CJCpvNbznMmFVfpzPTnriq0kYWtNemlOD6oInjEJhzlX/MAKiyokUXQ0qit/KLj+zLzuAH3F6pVaMRrXRn4VjzBw0wtn318NY07egehHXyWnZhyM9l0kHMf/ze9KlQNE6Sdg2p3vYo/Hq92jn1rRbO59GTtLfvxPn5QxqO6FkLHZ/88+48rGj194umjw35pFBKx4rrKzuzS4pWSvhkdzyrhRnTCVdMI7qC6QKCOzWDkQEVzuMBoOZzNkUwie7LrRumo3wMlr/8czcevewuo2IXNIzgD7TJxw98KoyA2iOs/gldXx3CPC4SiFaEvp6dq7I4fh8GdU0qF1MVOiPdvsoTrQQ5UWwcFD6h++pJRtaYAs0C+nUc9goj4CFBgjdYM+L4Dlgz5tEzQlMNUsnqXSXVhlVhkhC9yEZcOc5IrfZuT2dzHSy7+Qbe5nInBellfHBl+CWcEpWn/jjlwX9HL0m1ighHydAXVY+AV2URNDoOpHzWjwqPs8PpDN+JOoS9P98XRkJjFge+4Yje34H5B0XWticmtwtHcMefFIsWWY2QXorWYako3rd0RzGNYZyuYX2uCp8isVTcOvSqj/a8gFakwJ+4nV154Vi4eug2Wo+C5oGTWB4Hswx1HebZVaMqKvKRGbCdRkVX22oK6iyaAiiYpf5nB1Ep2AUAYg+Qx7ut96diFZLdXYFfNfoFZwVGussF8YCLj236NHMPrisyvb5av6Siy21oV3RqJshiJW95ZfJqpRrmbUTOdTCnJ9a7MZ47 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95a27da3-82a5-4fa4-cf2a-08d8c89cb345 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:42.3473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zk+fQUFRjPWPo8X09lgguRz1ZQvV/Q3+611J76qZ14X/Exg/9tU5P18MdXg55YsgQonrvMBApO+7wQjpLqZc+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This is just to define new enumerated type without functional change. The 'SWIOTLB_LO' is to index legacy 32-bit swiotlb buffer, while the 'SWIOTLB_HI' is to index the 64-bit buffer. This is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/swiotlb.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index d9c9fc9ca5d2..ca125c1b1281 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -17,6 +17,12 @@ enum swiotlb_force { SWIOTLB_NO_FORCE, /* swiotlb=noforce */ }; +enum swiotlb_t { + SWIOTLB_LO, + SWIOTLB_HI, + SWIOTLB_MAX, +}; + /* * Maximum allowable number of contiguous slabs to map, * must be a power of 2. What is the appropriate value ? From patchwork Wed Feb 3 23:37:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22874C433E0 for ; Wed, 3 Feb 2021 23:39:19 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A38D664F43 for ; Wed, 3 Feb 2021 23:39:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A38D664F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81096.149231 (Exim 4.92) (envelope-from ) id 1l7Rjq-0006LH-Ej; Wed, 03 Feb 2021 23:39:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81096.149231; Wed, 03 Feb 2021 23:39:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjq-0006LA-Ae; Wed, 03 Feb 2021 23:39:10 +0000 Received: by outflank-mailman (input) for mailman id 81096; Wed, 03 Feb 2021 23:39:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjp-00060K-GN for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:09 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f2930d99-fdfb-415f-9161-dc035662ec49; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N94Pp103917; Wed, 3 Feb 2021 23:37:52 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 36cydm2q1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:52 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NB4Nf025252; Wed, 3 Feb 2021 23:37:52 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by aserp3020.oracle.com with ESMTP id 36dhc1wj64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:51 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:48 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:48 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:42 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f2930d99-fdfb-415f-9161-dc035662ec49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=ymt145DO0qO8TYm1a8EXesRs01fgiJRugSzEz3L8IRKdQBTYNNcfAUB+RSZT40m0lM39 hT0O4IvkHJaQ3YjxBzh7fjBnWopdXNkkdzlGOnCTK+p7wr7kvSY7xYESFGKQfGNX/5AK 4wDAnYH83AMb50mWUSaasQk4TwKZDassXFqS6DbdFsL+GGA9K3Y6JNC3/hybO0fpiY6b cWuYhdxXTgMmDeQ/jHkvmpjk2ufoDbruAHJ73uSOB1/lYzO+9wak7PU7G3VIk9kuUTzE dLPLyCl3O1c3gqLwNfxmUuvWIya8O820xwCbtkv8ZZIA3Mhoy++AsgHriwsanUEndgAM RQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kHORM4V2tKdZdkRvag6BlOp1gQc6R3pnvwq4BJ05MpTLvFoH8CiLTNWzFjD5mORYszDmIQBOy66uGDYUw/owH7Gq5WnziLRoztgLfcjzbML2I+VcP/YmZ0YtqkZ/jFZVAStF00fkT4IIWoSkm3XLUP0A3fCBK727jkxBbw225t6FbWR5ZI6pigIgjU+y5JP5/41iNhRGir209Uew0ZdwkMFuIXIw7q649aWD5mjXE8CmOWPL7j0FynJfZt4k2YHtlMyRP7Z4x9yq85r5eElean/5WxDslhQ5j6ChYGIfDqNiMRfct/zi6i5GBKkjVtocdlyIabR9VdWrHDZU0QfJCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=lYqaTZ1gCuE0IaPruIsmjn+pEnTEG8UFYUTHtgKUmO2pAPbraM8USj+TQyiDb+9OLGoihxSc9KJYD6/rNsGzChdJSAsmu+MtCYS0cdv81qpQ+aMWwBA/wq2Fg0ewMOm3EGbKzJm3c8wGlfQ8ZuLccr0BRBQvtPMqwp2/uc3ftgUyckKQ5XqeAsAPe6wf4dz4he2e3LQ+G77YnSVfS4/LTI6nycd/nitj0KAAXo93Wo1w7JYbQXbkED0bQI6lF4+Thl/u5iUPu4mmmkZYD+6JnnlzUOKt9k6D8BbMtf8k0zU2xUOLeFZNti6gK34KhnAqdHe6ZFFZ83xaV3dEoNPR0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=KkkR4pWcwFNIbO525g642zO5aq6uRD472cAQzoWX9B9gnmZsp86vDwMDZMJWv9XzLoktBUgh8Q/RhcbTzZI1CrxP3E2z6Q6bsmZ+eV7pczJDUgT/RPy6direwT+yBCBUg0IlsigTH14Aysxhi912DxXdyYxeL+j/nWCHp4XxKag= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 2/6] swiotlb: convert variables to arrays Date: Wed, 3 Feb 2021 15:37:05 -0800 Message-Id: <20210203233709.19819-3-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6944969b-97db-45a0-60c0-08d8c89cb6bb X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:519; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nr78D0BKtGfvFg+Zfn+Ls1e+J8xHXLnIJvc4gVLi+ug2eClaIcZ6uhzFtYpjSTwp7e7R5plVXJ8NBrg9zON7LXhMatgSgfyGlEx91DqGFigMBLa4Nmq/47L/XpbNffcydvVTC0kxSIp97xQFN+wQj1yexDtR8ALIiO/dbrPMKOsdPxwSxtOSZoGgo21vH2w2zIPpeitK5rCORhh3jWnaWj/PfWhFWAUAysHzS3e0HzAybFNCXagGOyl4jmAoEWOG+BCGOTBBAkc1HA96vI0nujtkQssrb/WEJlDSa/h/cS+42jr4R2iEsogttCi/42xJGvKGof0y+JmB8c+0RQuGOfh/cmeSJTGOSEmS3xv9JBpUqJu4VWPBGhu288UKCmvW6rsIgd644MWC8WWJvZxQMmZUI8D/uaKp3kL92CaeLj4qk4nYG5n/0JJjnblSYTBdejKWy9hJ31wAgQ9Lu7C0hdDQiUxmZjM23VdjADjiGmUJGAJozKbN4McGomAArxPJWcYNMObna0G4jz412XvSAGLyJqlJ4Juxlc8uRj4OJmaMTg4XXTUAXWfuHXhDlH3yU0+DSq21chBMad/htHBMrEvB60yr4BTBW4ER+x38C3M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(30864003)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WYrdUlsRpAm3qmPfNVC56GiDTxiaAAF5RDWBwCeb1MA7PZAa7AztQi35fgIgjoIVm+NsV+Ah7jJJGlV4C/3sLzdgeF3L222clfsCi59UaNnXDM4oTZRfOt0F3UmtvFrkybHGvmbWbt6paglrSI3R/dBm0mGWzhWP51NkHkfEsY0QzUaBQ9MII5VeiExjTUj3mUkymQUcuJZD67uvmuZlkfAqKNnN6onUgkYRAdghXc8VyYaQkw2+Qka/eHlnHvDUdFPSurF2/oEGXe2OkaM4FzGUOO5df5PuqVVzYCsbO5pdPsvPjOIs5t/ppnFbTmyGjqJewvY8+PM+KV34tZFig6vdx2YTXtsLQSYXOb7bXnp+m4waCuEnynwdXSxRIAyD2DM14JPtzR3vtMuklmjsFla3p/wSLj5+TeXaEACzsAHOM/MXDubyFke02eTC1jtUsNcSnXt51XpDgXgtROTmvVQigPmfoDrJph4CQqa+zNk/LjkzYKIX7GUon18vkSWT+Z69KRioyesR/l2g1mU06fVzLlD4Nk0KxBGumDhO5E49v/gLbzBJne6BGW9N4STIsLKj3xLwiFbQz4Mhhphw/k/DdNKtAgmt/SKWp71gjcNdpdgdUVDvOFh2+iCb/IlAOhYTcnbkKmFyuLl/Bjsn6tOPAQ5K0mSk+3L5Iqpm6Aj9e8aYDi1aReE3eE3ZsPNPqOFS+VVQRUBdiKA+LWRN/aBP0m8D9w20N6d6nvI21mehLFfnG8KtJrxFy64I06UymiZFX2mZiNPG+Pq9fErWxR74DBC1KJn/LpDvK1Aoi5dfWK3BMZPPUoPhQD7JMXaCOtSVr7xmUTi19khibasCepAGlaohSQQWMzSOR9LIqKoWlk/AM1VJgZmQmXRwSe2IR/OGMsvNEI3rfRIOhwIuHT0xaT8N3qalx33VhrStF+SQCoHvKwT7wL47xmvXUaP2JoUGpiMn39DHFhMecx22MHUd+nVE/Ty3GireUN5CgFbhJv/Rbh/YTnWUsvquexuwJp1rqFe2wPt7gVRWU6wPpFrv/m1BWe6h3K15s8HVGR1g5f4oCessiCAoG/u7pE2P X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6944969b-97db-45a0-60c0-08d8c89cb6bb X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:48.2080 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: F2kKZBo1cJuaZ1vlofMVuU/CWkd5ocmk3yTATYVa2qs0VNH9hXYDL5HmeRJwljQjfwSD3en40D8igro5q/vAyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This patch converts several swiotlb related variables to arrays, in order to maintain stat/status for different swiotlb buffers. Here are variables involved: - io_tlb_start and io_tlb_end - io_tlb_nslabs and io_tlb_used - io_tlb_list - io_tlb_index - max_segment - io_tlb_orig_addr - no_iotlb_memory There is no functional change and this is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- arch/powerpc/platforms/pseries/svm.c | 6 +- drivers/xen/swiotlb-xen.c | 4 +- include/linux/swiotlb.h | 5 +- kernel/dma/swiotlb.c | 257 ++++++++++++++------------- 4 files changed, 140 insertions(+), 132 deletions(-) diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c index 7b739cc7a8a9..9f8842d0da1f 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -55,9 +55,9 @@ void __init svm_swiotlb_init(void) if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false)) return; - if (io_tlb_start) - memblock_free_early(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + if (io_tlb_start[SWIOTLB_LO]) + memblock_free_early(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); panic("SVM: Cannot allocate SWIOTLB buffer"); } diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 2b385c1b4a99..3261880ad859 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -192,8 +192,8 @@ int __ref xen_swiotlb_init(int verbose, bool early) /* * IO TLB memory already allocated. Just use it. */ - if (io_tlb_start != 0) { - xen_io_tlb_start = phys_to_virt(io_tlb_start); + if (io_tlb_start[SWIOTLB_LO] != 0) { + xen_io_tlb_start = phys_to_virt(io_tlb_start[SWIOTLB_LO]); goto end; } diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index ca125c1b1281..777046cd4d1b 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -76,11 +76,12 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys, #ifdef CONFIG_SWIOTLB extern enum swiotlb_force swiotlb_force; -extern phys_addr_t io_tlb_start, io_tlb_end; +extern phys_addr_t io_tlb_start[], io_tlb_end[]; static inline bool is_swiotlb_buffer(phys_addr_t paddr) { - return paddr >= io_tlb_start && paddr < io_tlb_end; + return paddr >= io_tlb_start[SWIOTLB_LO] && + paddr < io_tlb_end[SWIOTLB_LO]; } void __init swiotlb_exit(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 7c42df6e6100..1fbb65daa2dd 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -69,38 +69,38 @@ enum swiotlb_force swiotlb_force; * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this * API. */ -phys_addr_t io_tlb_start, io_tlb_end; +phys_addr_t io_tlb_start[SWIOTLB_MAX], io_tlb_end[SWIOTLB_MAX]; /* * The number of IO TLB blocks (in groups of 64) between io_tlb_start and * io_tlb_end. This is command line adjustable via setup_io_tlb_npages. */ -static unsigned long io_tlb_nslabs; +static unsigned long io_tlb_nslabs[SWIOTLB_MAX]; /* * The number of used IO TLB block */ -static unsigned long io_tlb_used; +static unsigned long io_tlb_used[SWIOTLB_MAX]; /* * This is a free list describing the number of free entries available from * each index */ -static unsigned int *io_tlb_list; -static unsigned int io_tlb_index; +static unsigned int *io_tlb_list[SWIOTLB_MAX]; +static unsigned int io_tlb_index[SWIOTLB_MAX]; /* * Max segment that we can provide which (if pages are contingous) will * not be bounced (unless SWIOTLB_FORCE is set). */ -static unsigned int max_segment; +static unsigned int max_segment[SWIOTLB_MAX]; /* * We need to save away the original address corresponding to a mapped entry * for the sync operations. */ #define INVALID_PHYS_ADDR (~(phys_addr_t)0) -static phys_addr_t *io_tlb_orig_addr; +static phys_addr_t *io_tlb_orig_addr[SWIOTLB_MAX]; /* * Protect the above data structures in the map and unmap calls @@ -113,9 +113,9 @@ static int __init setup_io_tlb_npages(char *str) { if (isdigit(*str)) { - io_tlb_nslabs = simple_strtoul(str, &str, 0); + io_tlb_nslabs[SWIOTLB_LO] = simple_strtoul(str, &str, 0); /* avoid tail segment of size < IO_TLB_SEGSIZE */ - io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); } if (*str == ',') ++str; @@ -123,40 +123,40 @@ setup_io_tlb_npages(char *str) swiotlb_force = SWIOTLB_FORCE; } else if (!strcmp(str, "noforce")) { swiotlb_force = SWIOTLB_NO_FORCE; - io_tlb_nslabs = 1; + io_tlb_nslabs[SWIOTLB_LO] = 1; } return 0; } early_param("swiotlb", setup_io_tlb_npages); -static bool no_iotlb_memory; +static bool no_iotlb_memory[SWIOTLB_MAX]; unsigned long swiotlb_nr_tbl(void) { - return unlikely(no_iotlb_memory) ? 0 : io_tlb_nslabs; + return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : io_tlb_nslabs[SWIOTLB_LO]; } EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); unsigned int swiotlb_max_segment(void) { - return unlikely(no_iotlb_memory) ? 0 : max_segment; + return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : max_segment[SWIOTLB_LO]; } EXPORT_SYMBOL_GPL(swiotlb_max_segment); void swiotlb_set_max_segment(unsigned int val) { if (swiotlb_force == SWIOTLB_FORCE) - max_segment = 1; + max_segment[SWIOTLB_LO] = 1; else - max_segment = rounddown(val, PAGE_SIZE); + max_segment[SWIOTLB_LO] = rounddown(val, PAGE_SIZE); } unsigned long swiotlb_size_or_default(void) { unsigned long size; - size = io_tlb_nslabs << IO_TLB_SHIFT; + size = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; return size ? size : (IO_TLB_DEFAULT_SIZE); } @@ -170,10 +170,10 @@ void __init swiotlb_adjust_size(unsigned long new_size) * architectures such as those supporting memory encryption to * adjust/expand SWIOTLB size for their use. */ - if (!io_tlb_nslabs) { + if (!io_tlb_nslabs[SWIOTLB_LO]) { size = ALIGN(new_size, 1 << IO_TLB_SHIFT); - io_tlb_nslabs = size >> IO_TLB_SHIFT; - io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + io_tlb_nslabs[SWIOTLB_LO] = size >> IO_TLB_SHIFT; + io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20); } @@ -181,15 +181,16 @@ void __init swiotlb_adjust_size(unsigned long new_size) void swiotlb_print_info(void) { - unsigned long bytes = io_tlb_nslabs << IO_TLB_SHIFT; + unsigned long bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; - if (no_iotlb_memory) { + if (no_iotlb_memory[SWIOTLB_LO]) { pr_warn("No low mem\n"); return; } - pr_info("mapped [mem %pa-%pa] (%luMB)\n", &io_tlb_start, &io_tlb_end, - bytes >> 20); + pr_info("mapped [mem %pa-%pa] (%luMB)\n", + &io_tlb_start[SWIOTLB_LO], &io_tlb_end[SWIOTLB_LO], + bytes >> 20); } /* @@ -203,11 +204,11 @@ void __init swiotlb_update_mem_attributes(void) void *vaddr; unsigned long bytes; - if (no_iotlb_memory || late_alloc) + if (no_iotlb_memory[SWIOTLB_LO] || late_alloc) return; - vaddr = phys_to_virt(io_tlb_start); - bytes = PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT); + vaddr = phys_to_virt(io_tlb_start[SWIOTLB_LO]); + bytes = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); memset(vaddr, 0, bytes); } @@ -219,38 +220,38 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) bytes = nslabs << IO_TLB_SHIFT; - io_tlb_nslabs = nslabs; - io_tlb_start = __pa(tlb); - io_tlb_end = io_tlb_start + bytes; + io_tlb_nslabs[SWIOTLB_LO] = nslabs; + io_tlb_start[SWIOTLB_LO] = __pa(tlb); + io_tlb_end[SWIOTLB_LO] = io_tlb_start[SWIOTLB_LO] + bytes; /* * Allocate and initialize the free list array. This array is used * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int)); - io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_list) + alloc_size = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int)); + io_tlb_list[SWIOTLB_LO] = memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_list[SWIOTLB_LO]) panic("%s: Failed to allocate %zu bytes align=0x%lx\n", __func__, alloc_size, PAGE_SIZE); - alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)); - io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_orig_addr) + alloc_size = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t)); + io_tlb_orig_addr[SWIOTLB_LO] = memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_orig_addr[SWIOTLB_LO]) panic("%s: Failed to allocate %zu bytes align=0x%lx\n", __func__, alloc_size, PAGE_SIZE); - for (i = 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; + for (i = 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { + io_tlb_list[SWIOTLB_LO][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; } - io_tlb_index = 0; - no_iotlb_memory = false; + io_tlb_index[SWIOTLB_LO] = 0; + no_iotlb_memory[SWIOTLB_LO] = false; if (verbose) swiotlb_print_info(); - swiotlb_set_max_segment(io_tlb_nslabs << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); return 0; } @@ -265,25 +266,25 @@ swiotlb_init(int verbose) unsigned char *vstart; unsigned long bytes; - if (!io_tlb_nslabs) { - io_tlb_nslabs = (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[SWIOTLB_LO]) { + io_tlb_nslabs[SWIOTLB_LO] = (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); } - bytes = io_tlb_nslabs << IO_TLB_SHIFT; + bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; /* Get IO TLB memory from the low pages */ vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO], verbose)) return; - if (io_tlb_start) { - memblock_free_early(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); - io_tlb_start = 0; + if (io_tlb_start[SWIOTLB_LO]) { + memblock_free_early(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); + io_tlb_start[SWIOTLB_LO] = 0; } pr_warn("Cannot allocate buffer"); - no_iotlb_memory = true; + no_iotlb_memory[SWIOTLB_LO] = true; } /* @@ -294,22 +295,22 @@ swiotlb_init(int verbose) int swiotlb_late_init_with_default_size(size_t default_size) { - unsigned long bytes, req_nslabs = io_tlb_nslabs; + unsigned long bytes, req_nslabs = io_tlb_nslabs[SWIOTLB_LO]; unsigned char *vstart = NULL; unsigned int order; int rc = 0; - if (!io_tlb_nslabs) { - io_tlb_nslabs = (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[SWIOTLB_LO]) { + io_tlb_nslabs[SWIOTLB_LO] = (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); } /* * Get IO TLB memory from the low pages */ - order = get_order(io_tlb_nslabs << IO_TLB_SHIFT); - io_tlb_nslabs = SLABS_PER_PAGE << order; - bytes = io_tlb_nslabs << IO_TLB_SHIFT; + order = get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; + bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, @@ -320,15 +321,15 @@ swiotlb_late_init_with_default_size(size_t default_size) } if (!vstart) { - io_tlb_nslabs = req_nslabs; + io_tlb_nslabs[SWIOTLB_LO] = req_nslabs; return -ENOMEM; } if (order != get_order(bytes)) { pr_warn("only able to allocate %ld MB\n", (PAGE_SIZE << order) >> 20); - io_tlb_nslabs = SLABS_PER_PAGE << order; + io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; } - rc = swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs); + rc = swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO]); if (rc) free_pages((unsigned long)vstart, order); @@ -337,10 +338,10 @@ swiotlb_late_init_with_default_size(size_t default_size) static void swiotlb_cleanup(void) { - io_tlb_end = 0; - io_tlb_start = 0; - io_tlb_nslabs = 0; - max_segment = 0; + io_tlb_end[SWIOTLB_LO] = 0; + io_tlb_start[SWIOTLB_LO] = 0; + io_tlb_nslabs[SWIOTLB_LO] = 0; + max_segment[SWIOTLB_LO] = 0; } int @@ -350,9 +351,9 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) bytes = nslabs << IO_TLB_SHIFT; - io_tlb_nslabs = nslabs; - io_tlb_start = virt_to_phys(tlb); - io_tlb_end = io_tlb_start + bytes; + io_tlb_nslabs[SWIOTLB_LO] = nslabs; + io_tlb_start[SWIOTLB_LO] = virt_to_phys(tlb); + io_tlb_end[SWIOTLB_LO] = io_tlb_start[SWIOTLB_LO] + bytes; set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); memset(tlb, 0, bytes); @@ -362,37 +363,37 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - io_tlb_list = (unsigned int *)__get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs * sizeof(int))); - if (!io_tlb_list) + io_tlb_list[SWIOTLB_LO] = (unsigned int *)__get_free_pages(GFP_KERNEL, + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + if (!io_tlb_list[SWIOTLB_LO]) goto cleanup3; - io_tlb_orig_addr = (phys_addr_t *) + io_tlb_orig_addr[SWIOTLB_LO] = (phys_addr_t *) __get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs * + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - if (!io_tlb_orig_addr) + if (!io_tlb_orig_addr[SWIOTLB_LO]) goto cleanup4; - for (i = 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; + for (i = 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { + io_tlb_list[SWIOTLB_LO][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; } - io_tlb_index = 0; - no_iotlb_memory = false; + io_tlb_index[SWIOTLB_LO] = 0; + no_iotlb_memory[SWIOTLB_LO] = false; swiotlb_print_info(); late_alloc = 1; - swiotlb_set_max_segment(io_tlb_nslabs << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); return 0; cleanup4: - free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs * + free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - io_tlb_list = NULL; + io_tlb_list[SWIOTLB_LO] = NULL; cleanup3: swiotlb_cleanup(); return -ENOMEM; @@ -400,23 +401,23 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) void __init swiotlb_exit(void) { - if (!io_tlb_orig_addr) + if (!io_tlb_orig_addr[SWIOTLB_LO]) return; if (late_alloc) { - free_pages((unsigned long)io_tlb_orig_addr, - get_order(io_tlb_nslabs * sizeof(phys_addr_t))); - free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs * - sizeof(int))); - free_pages((unsigned long)phys_to_virt(io_tlb_start), - get_order(io_tlb_nslabs << IO_TLB_SHIFT)); + free_pages((unsigned long)io_tlb_orig_addr[SWIOTLB_LO], + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); + free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + free_pages((unsigned long)phys_to_virt(io_tlb_start[SWIOTLB_LO]), + get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); } else { - memblock_free_late(__pa(io_tlb_orig_addr), - PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t))); - memblock_free_late(__pa(io_tlb_list), - PAGE_ALIGN(io_tlb_nslabs * sizeof(int))); - memblock_free_late(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + memblock_free_late(__pa(io_tlb_orig_addr[SWIOTLB_LO]), + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); + memblock_free_late(__pa(io_tlb_list[SWIOTLB_LO]), + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + memblock_free_late(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); } swiotlb_cleanup(); } @@ -465,7 +466,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start); + dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start[SWIOTLB_LO]); unsigned long flags; phys_addr_t tlb_addr; unsigned int nslots, stride, index, wrap; @@ -475,7 +476,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, unsigned long max_slots; unsigned long tmp_io_tlb_used; - if (no_iotlb_memory) + if (no_iotlb_memory[SWIOTLB_LO]) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer"); if (mem_encrypt_active()) @@ -518,11 +519,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, */ spin_lock_irqsave(&io_tlb_lock, flags); - if (unlikely(nslots > io_tlb_nslabs - io_tlb_used)) + if (unlikely(nslots > io_tlb_nslabs[SWIOTLB_LO] - io_tlb_used[SWIOTLB_LO])) goto not_found; - index = ALIGN(io_tlb_index, stride); - if (index >= io_tlb_nslabs) + index = ALIGN(io_tlb_index[SWIOTLB_LO], stride); + if (index >= io_tlb_nslabs[SWIOTLB_LO]) index = 0; wrap = index; @@ -530,7 +531,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, while (iommu_is_span_boundary(index, nslots, offset_slots, max_slots)) { index += stride; - if (index >= io_tlb_nslabs) + if (index >= io_tlb_nslabs[SWIOTLB_LO]) index = 0; if (index == wrap) goto not_found; @@ -541,39 +542,42 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, * contiguous buffers, we allocate the buffers from that slot * and mark the entries as '0' indicating unavailable. */ - if (io_tlb_list[index] >= nslots) { + if (io_tlb_list[SWIOTLB_LO][index] >= nslots) { int count = 0; for (i = index; i < (int) (index + nslots); i++) - io_tlb_list[i] = 0; - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && io_tlb_list[i]; i--) - io_tlb_list[i] = ++count; - tlb_addr = io_tlb_start + (index << IO_TLB_SHIFT); + io_tlb_list[SWIOTLB_LO][i] = 0; + for (i = index - 1; + (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && + io_tlb_list[SWIOTLB_LO][i]; + i--) + io_tlb_list[SWIOTLB_LO][i] = ++count; + tlb_addr = io_tlb_start[SWIOTLB_LO] + (index << IO_TLB_SHIFT); /* * Update the indices to avoid searching in the next * round. */ - io_tlb_index = ((index + nslots) < io_tlb_nslabs + io_tlb_index[SWIOTLB_LO] = ((index + nslots) < io_tlb_nslabs[SWIOTLB_LO] ? (index + nslots) : 0); goto found; } index += stride; - if (index >= io_tlb_nslabs) + if (index >= io_tlb_nslabs[SWIOTLB_LO]) index = 0; } while (index != wrap); not_found: - tmp_io_tlb_used = io_tlb_used; + tmp_io_tlb_used = io_tlb_used[SWIOTLB_LO]; spin_unlock_irqrestore(&io_tlb_lock, flags); if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n", - alloc_size, io_tlb_nslabs, tmp_io_tlb_used); + alloc_size, io_tlb_nslabs[SWIOTLB_LO], tmp_io_tlb_used); return (phys_addr_t)DMA_MAPPING_ERROR; found: - io_tlb_used += nslots; + io_tlb_used[SWIOTLB_LO] += nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); /* @@ -582,7 +586,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, * needed. */ for (i = 0; i < nslots; i++) - io_tlb_orig_addr[index+i] = orig_addr + (i << IO_TLB_SHIFT); + io_tlb_orig_addr[SWIOTLB_LO][index+i] = orig_addr + (i << IO_TLB_SHIFT); if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_TO_DEVICE); @@ -599,8 +603,8 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, { unsigned long flags; int i, count, nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; - int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; - phys_addr_t orig_addr = io_tlb_orig_addr[index]; + int index = (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr = io_tlb_orig_addr[SWIOTLB_LO][index]; /* * First, sync the memory before unmapping the entry @@ -619,23 +623,26 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, spin_lock_irqsave(&io_tlb_lock, flags); { count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? - io_tlb_list[index + nslots] : 0); + io_tlb_list[SWIOTLB_LO][index + nslots] : 0); /* * Step 1: return the slots to the free list, merging the * slots with superceeding slots */ for (i = index + nslots - 1; i >= index; i--) { - io_tlb_list[i] = ++count; - io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; + io_tlb_list[SWIOTLB_LO][i] = ++count; + io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; } /* * Step 2: merge the returned slots with the preceding slots, * if available (non zero) */ - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) - io_tlb_list[i] = ++count; + for (i = index - 1; + (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && + io_tlb_list[SWIOTLB_LO][i]; + i--) + io_tlb_list[SWIOTLB_LO][i] = ++count; - io_tlb_used -= nslots; + io_tlb_used[SWIOTLB_LO] -= nslots; } spin_unlock_irqrestore(&io_tlb_lock, flags); } @@ -644,8 +651,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, size_t size, enum dma_data_direction dir, enum dma_sync_target target) { - int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; - phys_addr_t orig_addr = io_tlb_orig_addr[index]; + int index = (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr = io_tlb_orig_addr[SWIOTLB_LO][index]; if (orig_addr == INVALID_PHYS_ADDR) return; @@ -716,7 +723,7 @@ bool is_swiotlb_active(void) * When SWIOTLB is initialized, even if io_tlb_start points to physical * address zero, io_tlb_end surely doesn't. */ - return io_tlb_end != 0; + return io_tlb_end[SWIOTLB_LO] != 0; } #ifdef CONFIG_DEBUG_FS @@ -726,8 +733,8 @@ static int __init swiotlb_create_debugfs(void) struct dentry *root; root = debugfs_create_dir("swiotlb", NULL); - debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs); - debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used); + debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs[SWIOTLB_LO]); + debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used[SWIOTLB_LO]); return 0; } From patchwork Wed Feb 3 23:37:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87E45C433E0 for ; Wed, 3 Feb 2021 23:39:13 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3207464E49 for ; Wed, 3 Feb 2021 23:39:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3207464E49 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81095.149219 (Exim 4.92) (envelope-from ) id 1l7Rjm-0006DZ-6r; Wed, 03 Feb 2021 23:39:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81095.149219; Wed, 03 Feb 2021 23:39:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjm-0006DQ-1Q; Wed, 03 Feb 2021 23:39:06 +0000 Received: by outflank-mailman (input) for mailman id 81095; Wed, 03 Feb 2021 23:39:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjk-00060K-GM for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:04 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cdbe6280-1a3a-4c32-8b14-6afa799c6e13; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9nvp104113; Wed, 3 Feb 2021 23:37:57 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 36cydm2q1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:57 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZPD083375; Wed, 3 Feb 2021 23:37:56 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by aserp3030.oracle.com with ESMTP id 36dh1rp03y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:56 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:54 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:54 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:48 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cdbe6280-1a3a-4c32-8b14-6afa799c6e13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=zphOpY06kD3+7Df7x1mRIRAudIRvGVbxfV7cm1VVALzVaZSFojCB+pC1TdF6+kyhyfzb zw9oF/i9Jchi8EOMKPzhFIW1kNwc+TDKDxJnkptpBsmZnoaVtsUoiBM7FejgZ6Wb5N2U VvUVF4YiNFcEyDlZHFFYMHqBWlAzWfcK3gbJfhbfLToNfdyKRvjeTLmRoHGcpsXK/P06 YabOHIUEmZ+/pENHIs5BZwh9W6R0gEZns8pQy97rO+ULFv37KBdlsoF47pA3QDP2wFeV pXGKqZ/W+qJrFG46V14gJuom5a/zmWjo4xljodpZnaKmieEerTBfh9roxByjB7vqJvSD yA== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gEf0apA+fXDQBhkVC7p6RZiPW2beDGTJR3LkceZiUkSsKDlLcNRDEu8E1RUZ3dgWW3myJscl18/EraARgi7vRA5bI07NqJRHhXCRH75UJW8H5ew8k7XI6IKjGY5l1aUeMLYQA9ud84B2ewTHlqDc55qRJPCaIO0PI8C23xF717q5jori67CvUsACD4t/z+b63w8PfWcda/EZE/M9GpNSmIw7FGjsXH2u6t127XHqmaeVW+s4pUYJmTXN/tXZ1W9Jw3YhV5H8eR53Wb5Hm+YXFEIlpeRNwowt6QgMV4Rg+oHWldmDkiXyed3LFNrUTYu20+kHcG5zl9omEJiAOTEfPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=EiRIIAV+sSfHbA+ePNhanxwPg1PWkEuScf9GKzP3zcbHvD+RyrfCz6G8PQrE2Sv5vKM6R/S8DZuSj/l9X2gUFLSoLZpoD8HGsTBJZEGRitUGeud7S2nUxbRrvLCiTRXSS/A1kLjDwRzY8FJAozzdCmWL5lGIxS7lAY09nbUCTmcEPxji1fV2UBcxH0cuxnJZnx+WNaHvwa84+aVB6sTxxt0lxUo5HPkmyWAH+JKPx9C8vnb3+DFO+V4eFIgg7mdjZ8mOJk+WNq476bTRNxHyKEBhrqxKdYO9opot2nR4drhsRxAEfVBrCnseyftZL6CcWr8QjKkdP2ReukhKdC1KEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=fIEZVuK8vikYtyA8/X72InpkX1VCyox7gcB4puyv3oe+AQIFBZB8t7LAmvH/gJtpDdyOUb0CM7ki4FYRV6TQX1ynrT3iJDkCW8ENf6cVoDcVaoMkMQJ7+zib8Mr7Qc1ebqDdOUUaun9cdrR7Z9khq7AC+KgVRdYiQ8b+2cnaA7E= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 3/6] swiotlb: introduce swiotlb_get_type() to calculate swiotlb buffer type Date: Wed, 3 Feb 2021 15:37:06 -0800 Message-Id: <20210203233709.19819-4-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2add3f4-4994-4ff3-7c96-08d8c89cba39 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RLsEchawOksK0kvC0O+w3T4N1PAe5DU17fjViBpDniy2b9oX4Ufj/Tfq8EWhO4frB7qnX0pHSdDvzHQ0ACCSnNWfnsvXXVueYSMQ5bSKOZehrHUM+9L4t9jd07zu4gKv68MoOqFldDvMmK/RiQtDnCKrSM2k9IjjrO+HS1Rlbcm5FzAPQvsMhdbyVoX7IEnuLpd15jB8NLzIr8vnz81spY0Jx9+eVAjhguDVPT9rRmXtSMC60dsfHS55lCeB2Vj8k4aIvEOCTXTSZp1WxfoYpfjD1hwoDYtSG88vstblEjYKKMuirJd4Js35MVoTNqUwk1P1X1Tj8qKpqNzOOpZRVFed6WoSshwWCHcsJNCGyLxjNYzcVdPLuONOZB908nFsFlXunhMqmi/lRV97Ls5v1hy4GLXqaK3/U1a54rGH4ZkOo5lV264z0LOuJRpB36z47uumkrbQ5UUuslWuE+eRzmwO+YcKeLFn4t+gWi1VYhe4eiRqpTWdJidXGRDw8aGQs8A3hCrTQL7tDzrV5iwAsjl0Ko2cLCh5WY7v/FkOx3gVL/dv/Q+VQhrCbgmuT3dI8Gj5pg09+18zfV4CFs9ZM9xmRdm24wkCCVIxO4FyP+g= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BcXfwKqgNX8nkepJT4kFsuW0EIqFSZAcYDSzc+4S9iOuag1d/bCyiGVHpKCl0xddX9Vt5u5HL+mT7aWb9G412UZ2PypY26RbGIwvafGZmfYU2ipDw60fgBI+2vlGJqSUe5+9mVeMO7ZexQhODHbppbGlB0dJiqh0hzET7CtRzkcaPOEBLeadeyD2nlmSlc5No2kjos3hDOdsYfccm3bdhp4+HospEB8JYSFBQXqymJD7f4Rvf55Ab6RpmXbwmZyMu7dHwmJz3Y8FcNNB0hWUXoaypkZRGSBlRVkZR9EmJd1pBxOl+Qww8yUt2ra7p1vhgyXbi0uzLhyHb+wMaAk5dmzqIdI6pvJLt2lQ0gmqXPRM8W01An6c1LGPJt98NXX3Vr2i2Ewg4A/ZYxzQxp8p7EOlopuUkptkk0dTsJSEkHiLb5d5VGS0uPxWoj2AWBgOtdoUSVkm4wnGdkVUTjl6bICOnosAxKISlt/aNZpaJfN1OdoUJDCwvK0FV06TLlUWCvgL7pQ3jkx04TFwALqHEw2h6pY8UjsnjBGnDqRx5abwprSSt98LprW8Ku7VTHgBjJTpkIS0lmowSvcGN+6GR/NyjjxnQLNfehLBjybnbFKE3xBGxAxm7JeEJx2T2+76mWmughTZ8blz9CHrXPVSjg2y+9HokLfKQTXsYCSR/6EVLJq9uq6awiLWDE0QCQckSWSHGVHuKG6JyAuG3C7KIfe6ui6VdJZs08ZGxFpymfTPuhIccI4SHGRlfi14K/rYU/MuaFJisAyqcQNK95FM7wog6nn4BC/mfaofm4rmej2BXxc2lB1iyJbjx1/wM2+GNYv7yTCjCN0hT5a+kx0Bw7AJfaYQ6O5V9qeLoIf28Y3J2IOqHv7lD3GlMsPXfQiTMPFNToBdrV4ZsFelex4fxzffuc7L6v4rbAo0nqBqbXlUY754pa3VgZv5RlUmqSzEFOPk8qIkDFXXYDZ0OJhx0HlhLiscF+5PyapcsSgifjkTUZkUBcvOV8YJadhJ2uP7WM1UsT0zHDD99sInRccYSNY1fvpPMQehmQx4uO9DwTC14NuAIjcqgFbu0tNfNU2D X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2add3f4-4994-4ff3-7c96-08d8c89cba39 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:53.9367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f2I/HMS0YUJZk/sk/Cx1bLMo0oJIxcGZe+VqnPykaL7Pm15QLnMEIREVpFCxosN1Z6mZbgwEQo0EBiVXG7K/oQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This patch introduces swiotlb_get_type() in order to calculate which swiotlb buffer the given DMA address is belong to. This is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/swiotlb.h | 14 ++++++++++++++ kernel/dma/swiotlb.c | 2 ++ 2 files changed, 16 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 777046cd4d1b..3d5980d77810 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -3,6 +3,7 @@ #define __LINUX_SWIOTLB_H #include +#include #include #include #include @@ -23,6 +24,8 @@ enum swiotlb_t { SWIOTLB_MAX, }; +extern int swiotlb_nr; + /* * Maximum allowable number of contiguous slabs to map, * must be a power of 2. What is the appropriate value ? @@ -84,6 +87,17 @@ static inline bool is_swiotlb_buffer(phys_addr_t paddr) paddr < io_tlb_end[SWIOTLB_LO]; } +static inline int swiotlb_get_type(phys_addr_t paddr) +{ + int i; + + for (i = 0; i < swiotlb_nr; i++) + if (paddr >= io_tlb_start[i] && paddr < io_tlb_end[i]) + return i; + + return -ENOENT; +} + void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 1fbb65daa2dd..c91d3d2c3936 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -109,6 +109,8 @@ static DEFINE_SPINLOCK(io_tlb_lock); static int late_alloc; +int swiotlb_nr = 1; + static int __init setup_io_tlb_npages(char *str) { From patchwork Wed Feb 3 23:37:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E183EC433DB for ; Wed, 3 Feb 2021 23:39:24 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68B0F64F43 for ; Wed, 3 Feb 2021 23:39:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68B0F64F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81097.149243 (Exim 4.92) (envelope-from ) id 1l7Rjw-0006V4-2g; Wed, 03 Feb 2021 23:39:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81097.149243; Wed, 03 Feb 2021 23:39:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjv-0006Uu-Uu; Wed, 03 Feb 2021 23:39:15 +0000 Received: by outflank-mailman (input) for mailman id 81097; Wed, 03 Feb 2021 23:39:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rju-00060K-Gd for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:14 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 25ce93c3-4e45-4ecb-b114-469d71a519c6; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9ap2053612; Wed, 3 Feb 2021 23:38:04 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 36cvyb2we9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:04 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAc2x112310; Wed, 3 Feb 2021 23:38:03 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3030.oracle.com with ESMTP id 36dhd0h9qf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:03 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:59 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:59 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:54 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 25ce93c3-4e45-4ecb-b114-469d71a519c6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=PDiUbWCP0RoZ0o+0J6rJ82slOeerEQmqJVyEs8T+MB0fEhBfsGsSWIwqwm28J2BUvfMx 3GhIn5+GC36EMv3B+VM8eymanh0ykin4S75rWtxZb+QFNQX0rDCjGBMkI0gqEpThb/uJ omXeDMO5ZDETMdUqWYPREYpc2NzB5FOvEWNAiPEMQJZsFqltz8PS1ve57hK79BP8KK4b DuinwA5fzl1srAvdpLjmDRpWqzeNS//FSO2lsdaaIJ0gyw1cPeFQNM1t/UvVqio3m+kf z1APfuDaF+0akGUX1oM47qB6e84KdbL6F8Z7kQyYmoztKHNkrwYGfNqY3xw98XA5bYN8 TQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2V8N3xyJCDJeonH32RZQlVQ3jWrn+DzvYDIYPRzfZIPKWdEUnvGUWRxVzr3IaA2r5K0sWr+mMda2VvZm7i281mTPMbUVG13mzN/s1k9XOuo9nY2Mg/EwspJQHXt/SHYA+JawBEQKUWA+MsWyURkOC1WPrlN373wWxbwQ+KWI6Gj20e+tE5dawri4ldj4eqRPrL7ukb8LT5zoj0mXIraqp7Lqf5IFNnoMgjoVLFHKIspbQxHqI1LlI/3JnIHz4TC9O/M8oGnoQ5dzAOeKhzaLRy+Tmfy+uCNrDVpV8ifA8EpIuBGZdcF387gqZVG9XCO0PEJndUgfc55JZbpTP+1uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=BxlqyxLITubnbBrCASW+DgmsD6m5lKdslOGtcgEEA3klheiMkFHvokQofbOz36W3nPGaPJLWwNXiwA2SNvLNV2RUbvx0f01Ng2eqFTCBOKdRGHCimI4mPsEDZUXZJJcoUUrv93VEMkZSDAgTbQGErkEYr8GD+ioPY6hX62SUNgnW4WR4sipV3s89DhfAmy0habEz8BXbBVfXRAWxTD2A83d+RO57WUgWCrDAt/+VAaHzrgGkfCZA71AG4ZvBduMF5ucIdJKeklVOr0xRTEnNRqR8M6k6xcm1QBZ51X52bU+UDDWekmdVMhKv+06hgJ4ttuXReK6uARxAaPBRT7wxGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=KBGnY6O3w2Ms4RJHjtgtaazCdGmZA33iy4XS3yPOkIcJmhvgtc8iVvTVgW7SHkiLMzZl51Sgkh57gfkguYZmsGZyKFYiaK9TT3/BZLhPsYEJdeeSisnb6COfLtX1Pegj3wHT3kXKurwWCk8QT0mGt6ukgaUqj0X5ph+jt7Buq1U= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 4/6] swiotlb: enable 64-bit swiotlb Date: Wed, 3 Feb 2021 15:37:07 -0800 Message-Id: <20210203233709.19819-5-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e551ef0-1c3f-43af-134e-08d8c89cbda4 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rbOoLbhvjEiDwHn8YwqCH2Td6GURxyVXGBbpEnzKivEpvSx1TMcc1tDPUXLm2G1iCCYpsHfGcyfK5XIBrrkdNzKgwWpTFllDUfRgGuhXvLvXV58G6oFYWt9hXdgAamvuPUnQbueb9oF8s4k2Ndyd8drmTH/hydLPayryGqY8IUH8ctaWDETvtZEy7xlWb5BaPjsTBQy8RUz4O6XNTteJa4m2yZrDk+fosLMy6sk6ILGjZhDX5dfs9P0N1l30DvDDuxo+gxdjtVqtQIA+KzaCMWiVtnMncLx04xkhSOhSQT7Qnz2cxkJMj74fTGRwZ/almYaVnuS044fZw21O+le6UKYMtMlcqp1ow9Uu6G+N+NXBNOZ+6+hdIlxFSuoeHWx+7RbD6FXUSP0ZGJqzqyCJTjR0vmTxyEkk2KXBPQamjbXTpMAXrWDBI2rwT9R6Qk/ENZ3Oh/c1xo9N0wZ24SeFO7M0dmWM5p9RYdcky2gtp4QKF3VCOb57QH/+F4WKnKPG/ZgKIISMZYgdgb1YGCNAMs5VmFkl8deuxiryaUTVtfdNfljtQG2h/TBV/LTWvwox9MMEmCOlbx4TlyJLcf5+81Fz24zPbZFUUumMxaXSCYvlwv3NrC9Y21FT63IIWAp9s158c5ATJozi/tWiZxsLiw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(30864003)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002)(461764006)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JhNrVSwnivNA0yGVGvlva5dhTOSQih9UrxRsxZKz4yH6/lyJBR0Ta03BdYsiEfizf+QiqksJDR/a50wFo0OxP+67Xc1taIThJ0dZoT0SeB10DaYsZxMSyv59iND8s8vlQIQjB+asig/RVQdH48TcaDcEY2mpYNwLhhcy/IogpyMs3MjbHDtwOFEvizRSi4XPnJkiA1KEUaA9lRq+0inM0ylqWxOjcSxyW+TxemaemDvNtyG9H8P/MaJZqNB3g5ypXpOCXXcG5hxXx4N2lQIW1a3T0vL61EIULNSs81ubumzhtLEwz1FCm4AXZMAXFn0IRkXXj0dVthKKuGFQaoPc9KRZNpSZBMrvEOgdAmPGsvt8Iu6gmUkmQQ4ff4hxoo7/sptgepb3AXrX/1LSl8RtOrzwUczumr2lRkYpbL77QVcFLWNZbHkfvc8brSIY8Lpbs3EKOHXgOlFjMeETOH6Swou3eXPEvDCU/6ijLg4w20HRk//A0yOmqeLhhrLn1iUxtFksdQ4ETSlXkpsofHKN6B2pzffC4NhDRawkeZCnoeoM+I06xOZYnDfawcIMpYCKUPBdcONRVEIPO01LHUQvPAPC0KvKVI9yINtDl33q3S90op3YH6MWHd3JucEZJeyy0gtk7w8NWmQ6Xd01r262QP13TUfZkrPwREs3TMnlr9ujfTFZ/BX7txjmf1eDDwJQQZG6iQCKBxROhMAVfx32ZMYy4GUlunJ++cB6bd5eHgucUERVOXFBQaOlxz8CELVKxm4r8JHJrFgFmJh9BgiZC0qoLmZR1/VJ6CmJKrhbboog5/COx7T4RcUAN8b34i3dcjhsqdPs15bBiXV84rDDITpi5ZcztoLQUQrIgZ9uYkXsbCaOHreg6l1SVMUuwUuzkRtQj4SbOjDgRCxZB/FGNPv9UUpo7O+5TVxxzpcxTlnwxaB06uzKn7bGkTsMnNONyPKQbk+muWeYNpIAMVqSHMnVoS+g/0TxEcmkZ/Ypwt+8utMehD9qEZ4rRLdhSm1BDIlsIvGoJWYx3QAouthQZOsiA5slqflXe3+vPcLLBXno4lEtbqGRij85zIrxnGER X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e551ef0-1c3f-43af-134e-08d8c89cbda4 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:59.7094 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o0/PqwuIPm+eM+UxJJTP5oTDHWgjhBJlGqrrr8kTAtm9rHRs7gOc3APX+g8HPiptyPbadCkPBGWyyZPafVE50A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 impostorscore=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This patch is to enable the 64-bit swiotlb buffer. The state of the art swiotlb pre-allocates <=32-bit memory in order to meet the DMA mask requirement for some 32-bit legacy device. Considering most devices nowadays support 64-bit DMA and IOMMU is available, the swiotlb is not used for most of the times, except: 1. The xen PVM domain requires the DMA addresses to both (1) less than the dma mask, and (2) continuous in machine address. Therefore, the 64-bit device may still require swiotlb on PVM domain. 2. From source code the AMD SME/SEV will enable SWIOTLB_FORCE. As a result it is always required to allocate from swiotlb buffer even the device dma mask is 64-bit. sme_early_init() -> if (sev_active()) swiotlb_force = SWIOTLB_FORCE; Therefore, this patch introduces the 2nd swiotlb buffer for 64-bit DMA access. For instance, the swiotlb_tbl_map_single() allocates from the 2nd 64-bit buffer if the device DMA mask is min_not_zero(*hwdev->dma_mask, hwdev->bus_dma_limit). The example to configure 64-bit swiotlb is "swiotlb=65536,524288,force" or "swiotlb=,524288,force", where 524288 is the size of 64-bit buffer. With the patch, the kernel will be able to allocate >4GB swiotlb buffer. This patch is only for swiotlb, not including xen-swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- arch/mips/cavium-octeon/dma-octeon.c | 3 +- arch/powerpc/kernel/dma-swiotlb.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 5 +- arch/x86/pci/sta2x11-fixup.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 4 +- drivers/gpu/drm/i915/i915_scatterlist.h | 2 +- drivers/gpu/drm/nouveau/nouveau_ttm.c | 2 +- drivers/mmc/host/sdhci.c | 2 +- drivers/pci/xen-pcifront.c | 2 +- drivers/xen/swiotlb-xen.c | 9 +- include/linux/swiotlb.h | 28 +- kernel/dma/swiotlb.c | 339 +++++++++++-------- 13 files changed, 238 insertions(+), 164 deletions(-) diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c index df70308db0e6..3480555d908a 100644 --- a/arch/mips/cavium-octeon/dma-octeon.c +++ b/arch/mips/cavium-octeon/dma-octeon.c @@ -245,6 +245,7 @@ void __init plat_swiotlb_setup(void) panic("%s: Failed to allocate %zu bytes align=%lx\n", __func__, swiotlbsize, PAGE_SIZE); - if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM) + if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, + SWIOTLB_LO, 1) == -ENOMEM) panic("Cannot allocate SWIOTLB buffer"); } diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c index fc7816126a40..88113318c53f 100644 --- a/arch/powerpc/kernel/dma-swiotlb.c +++ b/arch/powerpc/kernel/dma-swiotlb.c @@ -20,7 +20,7 @@ void __init swiotlb_detect_4g(void) static int __init check_swiotlb_enabled(void) { if (ppc_swiotlb_enable) - swiotlb_print_info(); + swiotlb_print_info(SWIOTLB_LO); else swiotlb_exit(); diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c index 9f8842d0da1f..77910e4ffad8 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -52,7 +52,7 @@ void __init svm_swiotlb_init(void) bytes = io_tlb_nslabs << IO_TLB_SHIFT; vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, SWIOTLB_LO, false)) return; if (io_tlb_start[SWIOTLB_LO]) diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c index c2cfa5e7c152..950624fd95a4 100644 --- a/arch/x86/kernel/pci-swiotlb.c +++ b/arch/x86/kernel/pci-swiotlb.c @@ -67,12 +67,15 @@ void __init pci_swiotlb_init(void) void __init pci_swiotlb_late_init(void) { + int i; + /* An IOMMU turned us off. */ if (!swiotlb) swiotlb_exit(); else { printk(KERN_INFO "PCI-DMA: " "Using software bounce buffering for IO (SWIOTLB)\n"); - swiotlb_print_info(); + for (i = 0; i < swiotlb_nr; i++) + swiotlb_print_info(i); } } diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c index 7d2525691854..c440520b2055 100644 --- a/arch/x86/pci/sta2x11-fixup.c +++ b/arch/x86/pci/sta2x11-fixup.c @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev) int size = STA2X11_SWIOTLB_SIZE; /* First instance: register your own swiotlb area */ dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size); - if (swiotlb_late_init_with_default_size(size)) + if (swiotlb_late_init_with_default_size(size), SWIOTLB_LO) dev_emerg(&pdev->dev, "init swiotlb failed\n"); } list_add(&instance->list, &sta2x11_instance_list); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c index ad22f42541bd..947683f2e568 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c @@ -42,10 +42,10 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj) max_order = MAX_ORDER; #ifdef CONFIG_SWIOTLB - if (swiotlb_nr_tbl()) { + if (swiotlb_nr_tbl(SWIOTLB_LO)) { unsigned int max_segment; - max_segment = swiotlb_max_segment(); + max_segment = swiotlb_max_segment(SWIOTLB_LO); if (max_segment) { max_segment = max_t(unsigned int, max_segment, PAGE_SIZE) >> PAGE_SHIFT; diff --git a/drivers/gpu/drm/i915/i915_scatterlist.h b/drivers/gpu/drm/i915/i915_scatterlist.h index 9cb26a224034..c63c7f6941f6 100644 --- a/drivers/gpu/drm/i915/i915_scatterlist.h +++ b/drivers/gpu/drm/i915/i915_scatterlist.h @@ -118,7 +118,7 @@ static inline unsigned int i915_sg_page_sizes(struct scatterlist *sg) static inline unsigned int i915_sg_segment_size(void) { - unsigned int size = swiotlb_max_segment(); + unsigned int size = swiotlb_max_segment(SWIOTLB_LO); if (size == 0) size = UINT_MAX; diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c index a37bc3d7b38b..0919b207ac47 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -321,7 +321,7 @@ nouveau_ttm_init(struct nouveau_drm *drm) } #if IS_ENABLED(CONFIG_SWIOTLB) && IS_ENABLED(CONFIG_X86) - need_swiotlb = !!swiotlb_nr_tbl(); + need_swiotlb = !!swiotlb_nr_tbl(SWIOTLB_LO); #endif ret = ttm_bo_device_init(&drm->ttm.bdev, &nouveau_bo_driver, diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 646823ddd317..1f7fb912d5a9 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -4582,7 +4582,7 @@ int sdhci_setup_host(struct sdhci_host *host) mmc->max_segs = SDHCI_MAX_SEGS; } else if (host->flags & SDHCI_USE_SDMA) { mmc->max_segs = 1; - if (swiotlb_max_segment()) { + if (swiotlb_max_segment(SWIOTLB_LO)) { unsigned int max_req_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; mmc->max_req_size = min(mmc->max_req_size, diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index c6fe0cfec0f6..9509ed9b4126 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -693,7 +693,7 @@ static int pcifront_connect_and_init_dma(struct pcifront_device *pdev) spin_unlock(&pcifront_dev_lock); - if (!err && !swiotlb_nr_tbl()) { + if (!err && !swiotlb_nr_tbl(SWIOTLB_LO)) { err = pci_xen_swiotlb_init_late(); if (err) dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 3261880ad859..662638093542 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -184,7 +184,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN; unsigned int repeat = 3; - xen_io_tlb_nslabs = swiotlb_nr_tbl(); + xen_io_tlb_nslabs = swiotlb_nr_tbl(SWIOTLB_LO); retry: bytes = xen_set_nslabs(xen_io_tlb_nslabs); order = get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); @@ -245,16 +245,17 @@ int __ref xen_swiotlb_init(int verbose, bool early) } if (early) { if (swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, - verbose)) + SWIOTLB_LO, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc = 0; } else - rc = swiotlb_late_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs); + rc = swiotlb_late_init_with_tbl(xen_io_tlb_start, + xen_io_tlb_nslabs, SWIOTLB_LO); end: xen_io_tlb_end = xen_io_tlb_start + bytes; if (!rc) - swiotlb_set_max_segment(PAGE_SIZE); + swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); return rc; error: diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 3d5980d77810..8ba45fddfb14 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -43,11 +43,14 @@ extern int swiotlb_nr; #define IO_TLB_DEFAULT_SIZE (64UL<<20) extern void swiotlb_init(int verbose); -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose); -extern unsigned long swiotlb_nr_tbl(void); +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type, int verbose); +extern unsigned long swiotlb_nr_tbl(enum swiotlb_t type); unsigned long swiotlb_size_or_default(void); -extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); -extern int swiotlb_late_init_with_default_size(size_t default_size); +extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type); +extern int swiotlb_late_init_with_default_size(size_t default_size, + enum swiotlb_t type); extern void __init swiotlb_update_mem_attributes(void); /* @@ -83,8 +86,13 @@ extern phys_addr_t io_tlb_start[], io_tlb_end[]; static inline bool is_swiotlb_buffer(phys_addr_t paddr) { - return paddr >= io_tlb_start[SWIOTLB_LO] && - paddr < io_tlb_end[SWIOTLB_LO]; + int i; + + for (i = 0; i < swiotlb_nr; i++) + if (paddr >= io_tlb_start[i] && paddr < io_tlb_end[i]) + return true; + + return false; } static inline int swiotlb_get_type(phys_addr_t paddr) @@ -99,7 +107,7 @@ static inline int swiotlb_get_type(phys_addr_t paddr) } void __init swiotlb_exit(void); -unsigned int swiotlb_max_segment(void); +unsigned int swiotlb_max_segment(enum swiotlb_t type); size_t swiotlb_max_mapping_size(struct device *dev); bool is_swiotlb_active(void); void __init swiotlb_adjust_size(unsigned long new_size); @@ -112,7 +120,7 @@ static inline bool is_swiotlb_buffer(phys_addr_t paddr) static inline void swiotlb_exit(void) { } -static inline unsigned int swiotlb_max_segment(void) +static inline unsigned int swiotlb_max_segment(enum swiotlb_t type) { return 0; } @@ -131,7 +139,7 @@ static inline void swiotlb_adjust_size(unsigned long new_size) } #endif /* CONFIG_SWIOTLB */ -extern void swiotlb_print_info(void); -extern void swiotlb_set_max_segment(unsigned int); +extern void swiotlb_print_info(enum swiotlb_t type); +extern void swiotlb_set_max_segment(unsigned int val, enum swiotlb_t type); #endif /* __LINUX_SWIOTLB_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index c91d3d2c3936..cd28db5b016a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -111,6 +111,11 @@ static int late_alloc; int swiotlb_nr = 1; +static const char * const swiotlb_name[] = { + "Low Mem", + "High Mem" +}; + static int __init setup_io_tlb_npages(char *str) { @@ -121,11 +126,25 @@ setup_io_tlb_npages(char *str) } if (*str == ',') ++str; + + if (isdigit(*str)) { + io_tlb_nslabs[SWIOTLB_HI] = simple_strtoul(str, &str, 0); + /* avoid tail segment of size < IO_TLB_SEGSIZE */ + io_tlb_nslabs[SWIOTLB_HI] = ALIGN(io_tlb_nslabs[SWIOTLB_HI], IO_TLB_SEGSIZE); + + swiotlb_nr = 2; + } + + if (*str == ',') + ++str; + if (!strcmp(str, "force")) { swiotlb_force = SWIOTLB_FORCE; } else if (!strcmp(str, "noforce")) { swiotlb_force = SWIOTLB_NO_FORCE; io_tlb_nslabs[SWIOTLB_LO] = 1; + if (swiotlb_nr > 1) + io_tlb_nslabs[SWIOTLB_HI] = 1; } return 0; @@ -134,24 +153,24 @@ early_param("swiotlb", setup_io_tlb_npages); static bool no_iotlb_memory[SWIOTLB_MAX]; -unsigned long swiotlb_nr_tbl(void) +unsigned long swiotlb_nr_tbl(enum swiotlb_t type) { - return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : io_tlb_nslabs[SWIOTLB_LO]; + return unlikely(no_iotlb_memory[type]) ? 0 : io_tlb_nslabs[type]; } EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); -unsigned int swiotlb_max_segment(void) +unsigned int swiotlb_max_segment(enum swiotlb_t type) { - return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : max_segment[SWIOTLB_LO]; + return unlikely(no_iotlb_memory[type]) ? 0 : max_segment[type]; } EXPORT_SYMBOL_GPL(swiotlb_max_segment); -void swiotlb_set_max_segment(unsigned int val) +void swiotlb_set_max_segment(unsigned int val, enum swiotlb_t type) { if (swiotlb_force == SWIOTLB_FORCE) - max_segment[SWIOTLB_LO] = 1; + max_segment[type] = 1; else - max_segment[SWIOTLB_LO] = rounddown(val, PAGE_SIZE); + max_segment[type] = rounddown(val, PAGE_SIZE); } unsigned long swiotlb_size_or_default(void) @@ -181,18 +200,18 @@ void __init swiotlb_adjust_size(unsigned long new_size) } } -void swiotlb_print_info(void) +void swiotlb_print_info(enum swiotlb_t type) { - unsigned long bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + unsigned long bytes = io_tlb_nslabs[type] << IO_TLB_SHIFT; - if (no_iotlb_memory[SWIOTLB_LO]) { - pr_warn("No low mem\n"); + if (no_iotlb_memory[type]) { + pr_warn("No low mem with %s\n", swiotlb_name[type]); return; } - pr_info("mapped [mem %pa-%pa] (%luMB)\n", - &io_tlb_start[SWIOTLB_LO], &io_tlb_end[SWIOTLB_LO], - bytes >> 20); + pr_info("%s mapped [mem %pa-%pa] (%luMB)\n", + swiotlb_name[type], + &io_tlb_start[type], &io_tlb_end[type], bytes >> 20); } /* @@ -205,88 +224,104 @@ void __init swiotlb_update_mem_attributes(void) { void *vaddr; unsigned long bytes; + int i; - if (no_iotlb_memory[SWIOTLB_LO] || late_alloc) - return; + for (i = 0; i < swiotlb_nr; i++) { + if (no_iotlb_memory[i] || late_alloc) + continue; - vaddr = phys_to_virt(io_tlb_start[SWIOTLB_LO]); - bytes = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); - set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); - memset(vaddr, 0, bytes); + vaddr = phys_to_virt(io_tlb_start[i]); + bytes = PAGE_ALIGN(io_tlb_nslabs[i] << IO_TLB_SHIFT); + set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); + memset(vaddr, 0, bytes); + } } -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type, int verbose) { unsigned long i, bytes; size_t alloc_size; bytes = nslabs << IO_TLB_SHIFT; - io_tlb_nslabs[SWIOTLB_LO] = nslabs; - io_tlb_start[SWIOTLB_LO] = __pa(tlb); - io_tlb_end[SWIOTLB_LO] = io_tlb_start[SWIOTLB_LO] + bytes; + io_tlb_nslabs[type] = nslabs; + io_tlb_start[type] = __pa(tlb); + io_tlb_end[type] = io_tlb_start[type] + bytes; /* * Allocate and initialize the free list array. This array is used * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - alloc_size = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int)); - io_tlb_list[SWIOTLB_LO] = memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_list[SWIOTLB_LO]) + alloc_size = PAGE_ALIGN(io_tlb_nslabs[type] * sizeof(int)); + io_tlb_list[type] = memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_list[type]) panic("%s: Failed to allocate %zu bytes align=0x%lx\n", __func__, alloc_size, PAGE_SIZE); - alloc_size = PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t)); - io_tlb_orig_addr[SWIOTLB_LO] = memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_orig_addr[SWIOTLB_LO]) + alloc_size = PAGE_ALIGN(io_tlb_nslabs[type] * sizeof(phys_addr_t)); + io_tlb_orig_addr[type] = memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_orig_addr[type]) panic("%s: Failed to allocate %zu bytes align=0x%lx\n", __func__, alloc_size, PAGE_SIZE); - for (i = 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { - io_tlb_list[SWIOTLB_LO][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; + for (i = 0; i < io_tlb_nslabs[type]; i++) { + io_tlb_list[type][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[type][i] = INVALID_PHYS_ADDR; } - io_tlb_index[SWIOTLB_LO] = 0; - no_iotlb_memory[SWIOTLB_LO] = false; + io_tlb_index[type] = 0; + no_iotlb_memory[type] = false; if (verbose) - swiotlb_print_info(); + swiotlb_print_info(type); - swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[type] << IO_TLB_SHIFT, type); return 0; } -/* - * Statically reserve bounce buffer space and initialize bounce buffer data - * structures for the software IO TLB used to implement the DMA API. - */ -void __init -swiotlb_init(int verbose) +static void __init +swiotlb_init_type(enum swiotlb_t type, int verbose) { size_t default_size = IO_TLB_DEFAULT_SIZE; unsigned char *vstart; unsigned long bytes; - if (!io_tlb_nslabs[SWIOTLB_LO]) { - io_tlb_nslabs[SWIOTLB_LO] = (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[type]) { + io_tlb_nslabs[type] = (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[type] = ALIGN(io_tlb_nslabs[type], IO_TLB_SEGSIZE); } - bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + bytes = io_tlb_nslabs[type] << IO_TLB_SHIFT; + + if (type == SWIOTLB_LO) + vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); + else + vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - /* Get IO TLB memory from the low pages */ - vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO], verbose)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[type], type, verbose)) return; - if (io_tlb_start[SWIOTLB_LO]) { - memblock_free_early(io_tlb_start[SWIOTLB_LO], - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); - io_tlb_start[SWIOTLB_LO] = 0; + if (io_tlb_start[type]) { + memblock_free_early(io_tlb_start[type], + PAGE_ALIGN(io_tlb_nslabs[type] << IO_TLB_SHIFT)); + io_tlb_start[type] = 0; } - pr_warn("Cannot allocate buffer"); - no_iotlb_memory[SWIOTLB_LO] = true; + pr_warn("Cannot allocate buffer %s\n", swiotlb_name[type]); + no_iotlb_memory[type] = true; +} + +/* + * Statically reserve bounce buffer space and initialize bounce buffer data + * structures for the software IO TLB used to implement the DMA API. + */ +void __init +swiotlb_init(int verbose) +{ + int i; + + for (i = 0; i < swiotlb_nr; i++) + swiotlb_init_type(i, verbose); } /* @@ -295,67 +330,68 @@ swiotlb_init(int verbose) * This should be just like above, but with some error catching. */ int -swiotlb_late_init_with_default_size(size_t default_size) +swiotlb_late_init_with_default_size(size_t default_size, enum swiotlb_t type) { - unsigned long bytes, req_nslabs = io_tlb_nslabs[SWIOTLB_LO]; + unsigned long bytes, req_nslabs = io_tlb_nslabs[type]; unsigned char *vstart = NULL; unsigned int order; int rc = 0; + gfp_t gfp_mask = (type == SWIOTLB_LO) ? GFP_DMA | __GFP_NOWARN : + GFP_KERNEL | __GFP_NOWARN; - if (!io_tlb_nslabs[SWIOTLB_LO]) { - io_tlb_nslabs[SWIOTLB_LO] = (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] = ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[type]) { + io_tlb_nslabs[type] = (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[type] = ALIGN(io_tlb_nslabs[type], IO_TLB_SEGSIZE); } /* * Get IO TLB memory from the low pages */ - order = get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; - bytes = io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + order = get_order(io_tlb_nslabs[type] << IO_TLB_SHIFT); + io_tlb_nslabs[type] = SLABS_PER_PAGE << order; + bytes = io_tlb_nslabs[type] << IO_TLB_SHIFT; while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, - order); + vstart = (void *)__get_free_pages(gfp_mask, order); if (vstart) break; order--; } if (!vstart) { - io_tlb_nslabs[SWIOTLB_LO] = req_nslabs; + io_tlb_nslabs[type] = req_nslabs; return -ENOMEM; } if (order != get_order(bytes)) { pr_warn("only able to allocate %ld MB\n", (PAGE_SIZE << order) >> 20); - io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; + io_tlb_nslabs[type] = SLABS_PER_PAGE << order; } - rc = swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO]); + rc = swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[type], type); if (rc) free_pages((unsigned long)vstart, order); return rc; } -static void swiotlb_cleanup(void) +static void swiotlb_cleanup(enum swiotlb_t type) { - io_tlb_end[SWIOTLB_LO] = 0; - io_tlb_start[SWIOTLB_LO] = 0; - io_tlb_nslabs[SWIOTLB_LO] = 0; - max_segment[SWIOTLB_LO] = 0; + io_tlb_end[type] = 0; + io_tlb_start[type] = 0; + io_tlb_nslabs[type] = 0; + max_segment[type] = 0; } int -swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) +swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs, enum swiotlb_t type) { unsigned long i, bytes; bytes = nslabs << IO_TLB_SHIFT; - io_tlb_nslabs[SWIOTLB_LO] = nslabs; - io_tlb_start[SWIOTLB_LO] = virt_to_phys(tlb); - io_tlb_end[SWIOTLB_LO] = io_tlb_start[SWIOTLB_LO] + bytes; + io_tlb_nslabs[type] = nslabs; + io_tlb_start[type] = virt_to_phys(tlb); + io_tlb_end[type] = io_tlb_start[type] + bytes; set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); memset(tlb, 0, bytes); @@ -365,63 +401,67 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - io_tlb_list[SWIOTLB_LO] = (unsigned int *)__get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - if (!io_tlb_list[SWIOTLB_LO]) + io_tlb_list[type] = (unsigned int *)__get_free_pages(GFP_KERNEL, + get_order(io_tlb_nslabs[type] * sizeof(int))); + if (!io_tlb_list[type]) goto cleanup3; - io_tlb_orig_addr[SWIOTLB_LO] = (phys_addr_t *) + io_tlb_orig_addr[type] = (phys_addr_t *) __get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs[SWIOTLB_LO] * + get_order(io_tlb_nslabs[type] * sizeof(phys_addr_t))); - if (!io_tlb_orig_addr[SWIOTLB_LO]) + if (!io_tlb_orig_addr[type]) goto cleanup4; - for (i = 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { - io_tlb_list[SWIOTLB_LO][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; + for (i = 0; i < io_tlb_nslabs[type]; i++) { + io_tlb_list[type][i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[type][i] = INVALID_PHYS_ADDR; } - io_tlb_index[SWIOTLB_LO] = 0; - no_iotlb_memory[SWIOTLB_LO] = false; + io_tlb_index[type] = 0; + no_iotlb_memory[type] = false; - swiotlb_print_info(); + swiotlb_print_info(type); late_alloc = 1; - swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[type] << IO_TLB_SHIFT, type); return 0; cleanup4: - free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], get_order(io_tlb_nslabs[SWIOTLB_LO] * + free_pages((unsigned long)io_tlb_list[type], get_order(io_tlb_nslabs[type] * sizeof(int))); - io_tlb_list[SWIOTLB_LO] = NULL; + io_tlb_list[type] = NULL; cleanup3: - swiotlb_cleanup(); + swiotlb_cleanup(type); return -ENOMEM; } void __init swiotlb_exit(void) { - if (!io_tlb_orig_addr[SWIOTLB_LO]) - return; + int i; - if (late_alloc) { - free_pages((unsigned long)io_tlb_orig_addr[SWIOTLB_LO], - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - free_pages((unsigned long)phys_to_virt(io_tlb_start[SWIOTLB_LO]), - get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); - } else { - memblock_free_late(__pa(io_tlb_orig_addr[SWIOTLB_LO]), - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - memblock_free_late(__pa(io_tlb_list[SWIOTLB_LO]), - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - memblock_free_late(io_tlb_start[SWIOTLB_LO], - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); + for (i = 0; i < swiotlb_nr; i++) { + if (!io_tlb_orig_addr[i]) + continue; + + if (late_alloc) { + free_pages((unsigned long)io_tlb_orig_addr[i], + get_order(io_tlb_nslabs[i] * sizeof(phys_addr_t))); + free_pages((unsigned long)io_tlb_list[i], + get_order(io_tlb_nslabs[i] * sizeof(int))); + free_pages((unsigned long)phys_to_virt(io_tlb_start[i]), + get_order(io_tlb_nslabs[i] << IO_TLB_SHIFT)); + } else { + memblock_free_late(__pa(io_tlb_orig_addr[i]), + PAGE_ALIGN(io_tlb_nslabs[i] * sizeof(phys_addr_t))); + memblock_free_late(__pa(io_tlb_list[i]), + PAGE_ALIGN(io_tlb_nslabs[i] * sizeof(int))); + memblock_free_late(io_tlb_start[i], + PAGE_ALIGN(io_tlb_nslabs[i] << IO_TLB_SHIFT)); + } + swiotlb_cleanup(i); } - swiotlb_cleanup(); } /* @@ -468,7 +508,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start[SWIOTLB_LO]); + dma_addr_t tbl_dma_addr; unsigned long flags; phys_addr_t tlb_addr; unsigned int nslots, stride, index, wrap; @@ -477,8 +517,16 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, unsigned long offset_slots; unsigned long max_slots; unsigned long tmp_io_tlb_used; + unsigned long dma_mask = min_not_zero(*hwdev->dma_mask, + hwdev->bus_dma_limit); + int type; - if (no_iotlb_memory[SWIOTLB_LO]) + if (swiotlb_nr > 1 && dma_mask == DMA_BIT_MASK(64)) + type = SWIOTLB_HI; + else + type = SWIOTLB_LO; + + if (no_iotlb_memory[type]) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer"); if (mem_encrypt_active()) @@ -490,6 +538,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, return (phys_addr_t)DMA_MAPPING_ERROR; } + tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start[type]); + mask = dma_get_seg_boundary(hwdev); tbl_dma_addr &= mask; @@ -521,11 +571,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, */ spin_lock_irqsave(&io_tlb_lock, flags); - if (unlikely(nslots > io_tlb_nslabs[SWIOTLB_LO] - io_tlb_used[SWIOTLB_LO])) + if (unlikely(nslots > io_tlb_nslabs[type] - io_tlb_used[type])) goto not_found; - index = ALIGN(io_tlb_index[SWIOTLB_LO], stride); - if (index >= io_tlb_nslabs[SWIOTLB_LO]) + index = ALIGN(io_tlb_index[type], stride); + if (index >= io_tlb_nslabs[type]) index = 0; wrap = index; @@ -533,7 +583,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, while (iommu_is_span_boundary(index, nslots, offset_slots, max_slots)) { index += stride; - if (index >= io_tlb_nslabs[SWIOTLB_LO]) + if (index >= io_tlb_nslabs[type]) index = 0; if (index == wrap) goto not_found; @@ -544,42 +594,42 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, * contiguous buffers, we allocate the buffers from that slot * and mark the entries as '0' indicating unavailable. */ - if (io_tlb_list[SWIOTLB_LO][index] >= nslots) { + if (io_tlb_list[type][index] >= nslots) { int count = 0; for (i = index; i < (int) (index + nslots); i++) - io_tlb_list[SWIOTLB_LO][i] = 0; + io_tlb_list[type][i] = 0; for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && - io_tlb_list[SWIOTLB_LO][i]; + io_tlb_list[type][i]; i--) - io_tlb_list[SWIOTLB_LO][i] = ++count; - tlb_addr = io_tlb_start[SWIOTLB_LO] + (index << IO_TLB_SHIFT); + io_tlb_list[type][i] = ++count; + tlb_addr = io_tlb_start[type] + (index << IO_TLB_SHIFT); /* * Update the indices to avoid searching in the next * round. */ - io_tlb_index[SWIOTLB_LO] = ((index + nslots) < io_tlb_nslabs[SWIOTLB_LO] + io_tlb_index[type] = ((index + nslots) < io_tlb_nslabs[type] ? (index + nslots) : 0); goto found; } index += stride; - if (index >= io_tlb_nslabs[SWIOTLB_LO]) + if (index >= io_tlb_nslabs[type]) index = 0; } while (index != wrap); not_found: - tmp_io_tlb_used = io_tlb_used[SWIOTLB_LO]; + tmp_io_tlb_used = io_tlb_used[type]; spin_unlock_irqrestore(&io_tlb_lock, flags); if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) - dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n", - alloc_size, io_tlb_nslabs[SWIOTLB_LO], tmp_io_tlb_used); + dev_warn(hwdev, "%s swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n", + swiotlb_name[type], alloc_size, io_tlb_nslabs[type], tmp_io_tlb_used); return (phys_addr_t)DMA_MAPPING_ERROR; found: - io_tlb_used[SWIOTLB_LO] += nslots; + io_tlb_used[type] += nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); /* @@ -588,7 +638,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, * needed. */ for (i = 0; i < nslots; i++) - io_tlb_orig_addr[SWIOTLB_LO][index+i] = orig_addr + (i << IO_TLB_SHIFT); + io_tlb_orig_addr[type][index+i] = orig_addr + (i << IO_TLB_SHIFT); if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_TO_DEVICE); @@ -605,8 +655,9 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, { unsigned long flags; int i, count, nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; - int index = (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; - phys_addr_t orig_addr = io_tlb_orig_addr[SWIOTLB_LO][index]; + int type = swiotlb_get_type(tlb_addr); + int index = (tlb_addr - io_tlb_start[type]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr = io_tlb_orig_addr[type][index]; /* * First, sync the memory before unmapping the entry @@ -625,14 +676,14 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, spin_lock_irqsave(&io_tlb_lock, flags); { count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? - io_tlb_list[SWIOTLB_LO][index + nslots] : 0); + io_tlb_list[type][index + nslots] : 0); /* * Step 1: return the slots to the free list, merging the * slots with superceeding slots */ for (i = index + nslots - 1; i >= index; i--) { - io_tlb_list[SWIOTLB_LO][i] = ++count; - io_tlb_orig_addr[SWIOTLB_LO][i] = INVALID_PHYS_ADDR; + io_tlb_list[type][i] = ++count; + io_tlb_orig_addr[type][i] = INVALID_PHYS_ADDR; } /* * Step 2: merge the returned slots with the preceding slots, @@ -640,11 +691,11 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, */ for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && - io_tlb_list[SWIOTLB_LO][i]; + io_tlb_list[type][i]; i--) - io_tlb_list[SWIOTLB_LO][i] = ++count; + io_tlb_list[type][i] = ++count; - io_tlb_used[SWIOTLB_LO] -= nslots; + io_tlb_used[type] -= nslots; } spin_unlock_irqrestore(&io_tlb_lock, flags); } @@ -653,8 +704,9 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, size_t size, enum dma_data_direction dir, enum dma_sync_target target) { - int index = (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; - phys_addr_t orig_addr = io_tlb_orig_addr[SWIOTLB_LO][index]; + int type = swiotlb_get_type(tlb_addr); + int index = (tlb_addr - io_tlb_start[type]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr = io_tlb_orig_addr[type][index]; if (orig_addr == INVALID_PHYS_ADDR) return; @@ -737,6 +789,15 @@ static int __init swiotlb_create_debugfs(void) root = debugfs_create_dir("swiotlb", NULL); debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs[SWIOTLB_LO]); debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used[SWIOTLB_LO]); + + if (swiotlb_nr == 1) + return 0; + + debugfs_create_ulong("io_tlb_nslabs-highmem", 0400, + root, &io_tlb_nslabs[SWIOTLB_HI]); + debugfs_create_ulong("io_tlb_used-highmem", 0400, + root, &io_tlb_used[SWIOTLB_HI]); + return 0; } From patchwork Wed Feb 3 23:37:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A304FC433DB for ; Wed, 3 Feb 2021 23:39:57 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 321B964F43 for ; Wed, 3 Feb 2021 23:39:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 321B964F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81103.149254 (Exim 4.92) (envelope-from ) id 1l7RkT-0006jL-KO; Wed, 03 Feb 2021 23:39:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81103.149254; Wed, 03 Feb 2021 23:39:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7RkT-0006jE-HA; Wed, 03 Feb 2021 23:39:49 +0000 Received: by outflank-mailman (input) for mailman id 81103; Wed, 03 Feb 2021 23:39:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7RkS-0006iz-6b for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:48 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a22cfbcb-3358-4927-91d6-092995ce037f; Wed, 03 Feb 2021 23:39:47 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9lJ4053674; Wed, 3 Feb 2021 23:38:09 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 36cvyb2weg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:08 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZjm083373; Wed, 3 Feb 2021 23:38:08 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by aserp3030.oracle.com with ESMTP id 36dh1rp0ay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:08 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:38:05 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:38:05 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:59 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a22cfbcb-3358-4927-91d6-092995ce037f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=pnoIjQjRAimCOZGBFABR649EZDLrKxG6Rg+Koe7dVE64t/PjnvnPZt/5g7CWcLP5cu52 P6eBa7EAlCqK/BoeTW6vxGAfUKSPLS3hYYUXkTTMlMMLrZJQygd0WggDf/bNlyJP8Ach upL7IU+DgF9INdgJ9Jy5KwJ94emFs97z0p49t0KEbZLYH0NU/Sb0NQHW/ppSJ3yG26o3 UeDWaKBcm9re+ww+zpHOsdb45vWIIZeVvU1aF7NtPhh3qxt8DftSnQAzVNbztT7vRnVD YMckMHkzfZaqs8LhaE/YbExCu0PPhS2LoJDTbRxu8k6i93v+Qr81JeiCNCaVBw2IXiJY gw== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JmNqAIq6lFOC9ainynSrQWiPZxnortBSHQvRtJoXz7LQpCjd3M+ye/KymfgLmc4EJeh2XCmLTv7sCAmczKH9xO6EESx5QQPcX+Pi7PAwsZHkIVs9jytyNBNZzT7htfvXU2mXGVhPDPF8lK3ulnVkvhUwo1A5ir4EXEtkyels3vUl6KvXxEcvwIm2MDJFYwcUTqh/UucspnoQEOV8WVWhuFYFSq2XCUiFEB4+Ab3cFD3LxCQ4ykD/RpE+H12AZCxjEr7u/lzXFuPUI8Zv0e3N5tAI592Tt8HieDU7Kvn4pctbe3RetR/iBRoUwm+WRjHjjpFa08O/i2TIZv7u00nzoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=A0ZPOADVVWV+Uj0/W8XGR394r9l5spc0nvzBnJvU0/rTEDb6RY8kZCTqRuBygUm03fprvI9YUgzPZSqNagCDc+RUmdqhN5fGnTrQjiBIWvB/iSZEi9cZNa0Wo+8mJ0cCs/gG2FQ7dICg5b0HcPS/TXK+Oul2GPKEgXO+M9AgitIDNtj+krmSsZ/d16skFak7nXurOhCJV2OykyOc5O43pjwcbIGL0mGuIPyxH7Fh3saJ2ELcsTlsC9i+mJQF5CBt5B9t9dRRTbxRDywZI2QkUHhz2fNRvEnMnX7d3RBnwoXQjwgTdZ4+zhrHBk6KPPfcFnXVslNmWK5xJfg/uCzk/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=SuQhKsBZuPC3v2+9NTZ3wq0i3I8MSiWjwvz1ZyiiwHaXki6ngpjRZXZixVoFMMxGo7dPX/PYBT1Mt+IFEMuaxqcskcFwb4xhYy3KAWa+xsYaoLVcsDiiDtHDgTrC9Xu95xQBHdW8C8/ibsPNos9Abpi3nPaCoF7GwaiyZTzlIDU= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 5/6] xen-swiotlb: convert variables to arrays Date: Wed, 3 Feb 2021 15:37:08 -0800 Message-Id: <20210203233709.19819-6-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55a79f1c-f122-4636-8dd4-08d8c89cc12c X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:173; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w77riGtFxYZxbwSzlnLDDwaRSpIhQOZiCo7C6NAvJRIvk6fyvrnj5N07AptsCQM8Ls9ytt1iCLVQDJZYrEFBvlTjOhbcE9YJtxeD1SD4ad6x9UmE3mT0P2uDXh8kPTr3JlWDod/q2PNM7LqKgCTowQDE8jXR2bOUVt4ix3LvHciJZ4Xcq7H2GXDhKzdwXTKGu5Mgc/3Qev9FMhOZQ9g17mKuf9xfaYHfo6Dx/rzxrLP/DVQdxytqGBIVhk2jo8iq4rZtbHv6iYSfNqY00vHZ5r8pP9r/N/sEP6WDw/6JBKAm61IGhvf3fQ4beQAIaqw1aErcezXYVibpPmEofuXM6cDBnRgIULXs8zoronpTqW1+mLoTnkuCPvTmeSFbnUNJrCY5zMjfLQ0N8HxWz9APVN7Nik94Ev2ddkvwXkbddkqR7lfedjlniJnS/LArFITW5iqTd/xi5Rd/D2U5fDK3tMSSEh3gesvmGePlvsfgi7IXv3dlgzrdtausINCULlW0JpnJJvTOLkHQAU9XC0cmLmrBmfA2STeUzp5HCTZj+w5DWGhq4YRjzIAX8fbqqj3pDjD9QI5Ij9O9xtbwOV6yI4oi1pFIVamN9ei02syvNXM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JOaqLB/L6hqA4VUE0kNmiLvAjzCeznvsu3Cr6DfHJWdEzSttbELTyL58Z9LLahqD02oPjGOF/MLn+QNete/4x2BQJuL4BmpjZaT5x3TRnVBy3Wlh9xgE8fsVVVNkDHHxkITVzis4PdWG8B7PXb6R3xPxM0QnENF0AWmWS0HLV//9XazhbpcKXmpD7trzVCKsUv/WpjcjAGMVXKneA5Yx9kIDfqSh2UhvuP/rH/n+QP8S4tapug1ebPrVG9itaWj+Eo7WgCgjWKxoSAvVt+KOeHIWfRLUqo/YZv/PNnGFKZ+yNRYwucUzawHwv9EQHRyZFuai97VEQVwIwWJ2DLh++ktFL0aowH4Gvmdd8Z90ZfR5Q7VdIg8DkVImvEfkossqIUJsaLEFQDuZd8Nz+NKlaD0i9iv7xZ94+Hj9Ief7D+OF+3JggwgSKfljSwLBJL/KWwEDLU2o0d4d7quP9dsYji4Rn3zSQXCXYHnRjGhSYQlYYS/8C26DWtMF625wdFu5CBgdLqNzwb+3zPvxYRevw5JfCUgWWFrWq3wn6Q7MAEKly0t06OpKuQ0D+oCxW4p+ne5TOvvdBZtPbsP4j2KQc6L4pTDqTV9cebXeNKgw6DSqPvEugv2EDgIyLGfD9/zqWV/bhTwdKCyRNx9bhc2E1OTjvA+ijbnKDcbZyG8qz24UhYVmZ3I9zq5gwD9KSfRvOIYTra0O5OBpz0j4UQmsYodAQ6aGaxH1t8bAK5xJpBz5YosKCtXuFLJ3woygzLUCpZP18fLGTX0kZ5i4YGVXoEOHmO6CegU0vYFLYpo8Q7bhGQZZkC/3xIO/eJ3swYnN35uaLnrhLkALh+TdMNC8nTUvCIKwfWipsx0goweO3wb6MA7OD16mRv9YAvLKVcGdEWhn29dEIbdkSRoPkfangpUGDOiCXyr1ikK8v7DWDY+Fqy6sP0ws4RBvDBzPZAdK5pnYA67j39+xPNsLLKTIWA534gYGFUyyumFunSj+nTgjPmhYRHfKLKuwGfQWCFj1qI/H08Qh4n7CyGJB+7XEsrHq52oARzMGKYALm/GGwT1TOFAH/QKk8Ixgczp2pmvr X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55a79f1c-f122-4636-8dd4-08d8c89cc12c X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:38:05.6010 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jUSQZrsRsfIIenrB0i+mXbNWLbyi4KAfiByVhFlKYSye86P0YY8sKEgjzQs4qhhWqfZ1mhwlltkYXlrN55IWjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 impostorscore=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This patch converts several xen-swiotlb related variables to arrays, in order to maintain stat/status for different swiotlb buffers. Here are variables involved: - xen_io_tlb_start and xen_io_tlb_end - xen_io_tlb_nslabs - MAX_DMA_BITS There is no functional change and this is to prepare to enable 64-bit xen-swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/xen/swiotlb-xen.c | 75 +++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 662638093542..e18cae693cdc 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -39,15 +39,17 @@ #include #include -#define MAX_DMA_BITS 32 /* * Used to do a quick range check in swiotlb_tbl_unmap_single and * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this * API. */ -static char *xen_io_tlb_start, *xen_io_tlb_end; -static unsigned long xen_io_tlb_nslabs; +static char *xen_io_tlb_start[SWIOTLB_MAX], *xen_io_tlb_end[SWIOTLB_MAX]; +static unsigned long xen_io_tlb_nslabs[SWIOTLB_MAX]; + +static int max_dma_bits[] = {32, 64}; + /* * Quick lookup value of the bus address of the IOTLB. */ @@ -112,8 +114,8 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr) * in our domain. Therefore _only_ check address within our domain. */ if (pfn_valid(PFN_DOWN(paddr))) { - return paddr >= virt_to_phys(xen_io_tlb_start) && - paddr < virt_to_phys(xen_io_tlb_end); + return paddr >= virt_to_phys(xen_io_tlb_start[SWIOTLB_LO]) && + paddr < virt_to_phys(xen_io_tlb_end[SWIOTLB_LO]); } return 0; } @@ -137,7 +139,7 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) p + (i << IO_TLB_SHIFT), get_order(slabs << IO_TLB_SHIFT), dma_bits, &dma_handle); - } while (rc && dma_bits++ < MAX_DMA_BITS); + } while (rc && dma_bits++ < max_dma_bits[SWIOTLB_LO]); if (rc) return rc; @@ -148,12 +150,13 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) static unsigned long xen_set_nslabs(unsigned long nr_tbl) { if (!nr_tbl) { - xen_io_tlb_nslabs = (64 * 1024 * 1024 >> IO_TLB_SHIFT); - xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE); + xen_io_tlb_nslabs[SWIOTLB_LO] = (64 * 1024 * 1024 >> IO_TLB_SHIFT); + xen_io_tlb_nslabs[SWIOTLB_LO] = ALIGN(xen_io_tlb_nslabs[SWIOTLB_LO], + IO_TLB_SEGSIZE); } else - xen_io_tlb_nslabs = nr_tbl; + xen_io_tlb_nslabs[SWIOTLB_LO] = nr_tbl; - return xen_io_tlb_nslabs << IO_TLB_SHIFT; + return xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; } enum xen_swiotlb_err { @@ -184,16 +187,16 @@ int __ref xen_swiotlb_init(int verbose, bool early) enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN; unsigned int repeat = 3; - xen_io_tlb_nslabs = swiotlb_nr_tbl(SWIOTLB_LO); + xen_io_tlb_nslabs[SWIOTLB_LO] = swiotlb_nr_tbl(SWIOTLB_LO); retry: - bytes = xen_set_nslabs(xen_io_tlb_nslabs); - order = get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); + bytes = xen_set_nslabs(xen_io_tlb_nslabs[SWIOTLB_LO]); + order = get_order(xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); /* * IO TLB memory already allocated. Just use it. */ if (io_tlb_start[SWIOTLB_LO] != 0) { - xen_io_tlb_start = phys_to_virt(io_tlb_start[SWIOTLB_LO]); + xen_io_tlb_start[SWIOTLB_LO] = phys_to_virt(io_tlb_start[SWIOTLB_LO]); goto end; } @@ -201,76 +204,78 @@ int __ref xen_swiotlb_init(int verbose, bool early) * Get IO TLB memory from any location. */ if (early) { - xen_io_tlb_start = memblock_alloc(PAGE_ALIGN(bytes), + xen_io_tlb_start[SWIOTLB_LO] = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (!xen_io_tlb_start) + if (!xen_io_tlb_start[SWIOTLB_LO]) panic("%s: Failed to allocate %lu bytes align=0x%lx\n", __func__, PAGE_ALIGN(bytes), PAGE_SIZE); } else { #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - xen_io_tlb_start = (void *)xen_get_swiotlb_free_pages(order); - if (xen_io_tlb_start) + xen_io_tlb_start[SWIOTLB_LO] = (void *)xen_get_swiotlb_free_pages(order); + if (xen_io_tlb_start[SWIOTLB_LO]) break; order--; } if (order != get_order(bytes)) { pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n", (PAGE_SIZE << order) >> 20); - xen_io_tlb_nslabs = SLABS_PER_PAGE << order; - bytes = xen_io_tlb_nslabs << IO_TLB_SHIFT; + xen_io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; + bytes = xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; } } - if (!xen_io_tlb_start) { + if (!xen_io_tlb_start[SWIOTLB_LO]) { m_ret = XEN_SWIOTLB_ENOMEM; goto error; } /* * And replace that memory with pages under 4GB. */ - rc = xen_swiotlb_fixup(xen_io_tlb_start, + rc = xen_swiotlb_fixup(xen_io_tlb_start[SWIOTLB_LO], bytes, - xen_io_tlb_nslabs); + xen_io_tlb_nslabs[SWIOTLB_LO]); if (rc) { if (early) - memblock_free(__pa(xen_io_tlb_start), + memblock_free(__pa(xen_io_tlb_start[SWIOTLB_LO]), PAGE_ALIGN(bytes)); else { - free_pages((unsigned long)xen_io_tlb_start, order); - xen_io_tlb_start = NULL; + free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); + xen_io_tlb_start[SWIOTLB_LO] = NULL; } m_ret = XEN_SWIOTLB_EFIXUP; goto error; } if (early) { - if (swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, + if (swiotlb_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], + xen_io_tlb_nslabs[SWIOTLB_LO], SWIOTLB_LO, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc = 0; } else - rc = swiotlb_late_init_with_tbl(xen_io_tlb_start, - xen_io_tlb_nslabs, SWIOTLB_LO); + rc = swiotlb_late_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], + xen_io_tlb_nslabs[SWIOTLB_LO], + SWIOTLB_LO); end: - xen_io_tlb_end = xen_io_tlb_start + bytes; + xen_io_tlb_end[SWIOTLB_LO] = xen_io_tlb_start[SWIOTLB_LO] + bytes; if (!rc) swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); return rc; error: if (repeat--) { - xen_io_tlb_nslabs = max(1024UL, /* Min is 2MB */ - (xen_io_tlb_nslabs >> 1)); + xen_io_tlb_nslabs[SWIOTLB_LO] = max(1024UL, /* Min is 2MB */ + (xen_io_tlb_nslabs[SWIOTLB_LO] >> 1)); pr_info("Lowering to %luMB\n", - (xen_io_tlb_nslabs << IO_TLB_SHIFT) >> 20); + (xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT) >> 20); goto retry; } pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc); if (early) panic("%s (rc:%d)", xen_swiotlb_error(m_ret), rc); else - free_pages((unsigned long)xen_io_tlb_start, order); + free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); return rc; } @@ -561,7 +566,7 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, static int xen_swiotlb_dma_supported(struct device *hwdev, u64 mask) { - return xen_virt_to_bus(hwdev, xen_io_tlb_end - 1) <= mask; + return xen_virt_to_bus(hwdev, xen_io_tlb_end[SWIOTLB_LO] - 1) <= mask; } const struct dma_map_ops xen_swiotlb_dma_ops = { From patchwork Wed Feb 3 23:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12065765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A14AC433E0 for ; Wed, 3 Feb 2021 23:41:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F195B64DF2 for ; Wed, 3 Feb 2021 23:41:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F195B64DF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.81106.149267 (Exim 4.92) (envelope-from ) id 1l7Rlm-0007b7-1D; Wed, 03 Feb 2021 23:41:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 81106.149267; Wed, 03 Feb 2021 23:41:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rll-0007b0-SH; Wed, 03 Feb 2021 23:41:09 +0000 Received: by outflank-mailman (input) for mailman id 81106; Wed, 03 Feb 2021 23:41:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rll-0007as-0R for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:41:09 +0000 Received: from userp2130.oracle.com (unknown [156.151.31.86]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ce2f8cf3-523f-4670-ab35-31b8a9e56a40; Wed, 03 Feb 2021 23:41:07 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAGKe046541; Wed, 3 Feb 2021 23:40:15 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 36cxvr5fk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:40:15 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZKB083400; Wed, 3 Feb 2021 23:38:14 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by aserp3030.oracle.com with ESMTP id 36dh1rp0e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:14 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:38:11 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:38:11 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:38:05 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ce2f8cf3-523f-4670-ab35-31b8a9e56a40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=AQgAsmYNKDuhJEXkKCCLjZ4btVMHNAaabw7AQaLEHjRQ1DxQ6rsmXgUd7yOAwDKP9eE6 /jn8Fue+dSJnNLWUz8OvbspBrcSBTd2mFnhKJJYcoRiHLkKv0pQ8floQsGn4dTpuwT0r XCDo8DnyDk48OzkHCP/OfGRAcLmqeSD7XxwLuh5HakhRJ5fe0Xig1IQqnm5Sxz235Ir8 mKVab/Wc+yzfaXw0POZyJ5aL5Tt0Magst+aUTkPD5NEilXYr61/hnUQYX8qpWRJVIPie lYzpfQkSuh7hAS2ER2mkomqrQd0Q61hS4+sZxC14yRf+48hMe4kXNeamnh4m+vxdT9M4 3w== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bzvh6TTjCKW6F/TBlPDxODMljmdU5b4U3YAZ35m4YjhLwwteroxdqRsIJXe6JrhtN/uUMUOElMzdZF1C1ENAr/iL1fuHxcW3WJ9TRa2Y0XqOGJ2RXu4LZVIpUtij3CG7vhsmbZ1bGXtFSLQSpltPFLoYkclDIu0iNCjpPLnCFanCiIOQeozHW9gQkSabewgu0PiVkxwh2PAy2tiAC2ZMA4AA/5FujqwuP3Nlw9VXAGOYvJkIEMSbYJTTzYk4PkLiBnJZ210q0KU4xFKDBtqO2M/kgU6/BGf2v2p/32pOyIlvd4KGSKYlFzG8qCSOW5qaNusG35HP52alvI07I30YpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=NsRvqL3XdcmO+sHJOG6vt9wkb0lFGLkVs6UQrK32rQH1C6R8jsab1XeW9C+xmQrrhtcwtO5GxWPtzwIXzsM8O9wJTXQuqvAStPW7TRG97ZtI5TvX4TDX6474kqE5dKXn6VUYTXneJWWSzuWVrQRtaDNPHYyje0YbkIJyeB0DNXmsHkgkcQhXEOq3Mo/jyelM3Gwashr8bKF3DUTo1jq+QEbtnAJ01VklerV71acJhDvDy7a/Ire8LPupCxJia7la3+S9IN8ZGoTIvoRHTyek2iSGphT1pDOi/CDJt7lme8U5szvXIZQNUyJQ0o071z+guAhUzAl1uYzMbs5TORkCbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=SH5E9mnI9UFqO/gUOeqFccVa5MYZdZsvoeyx68oFPHzx3hPsNVbSgm9Rh0xvUBc3Y2BlVvygdWv1haxHsNTj+TY77T6AJnfyqKjAeQADPPtP4bn59/aq76NOgrPOqOgNASnEzJEpRGcsQNg612h1i32PshXf4qIM/gTJXU7V5V8= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 6/6] xen-swiotlb: enable 64-bit xen-swiotlb Date: Wed, 3 Feb 2021 15:37:09 -0800 Message-Id: <20210203233709.19819-7-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a6f39ca-831d-4584-1671-08d8c89cc4a6 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:136; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g1MdwF09ZQsQBk3V9QOQLj3Q2J4L21DedJnj5zLtjikYKElnwxG4upLd7TjhmJPnAU7VpjSHxPeJkqoPBRqm6qLeK0CHlFugspJnxi0iJI55XYooo19FwHgiOqBWBro0DzURhQTcUKHg2pt6GcgakcdWtajKr7YhF2oMlQ9TwO3PVCjJBIHzVB9ARp0nbm7zuhWes6OM0DRHYiZShiKkwZu7s9DdAyEDvWn/Gl0ZL4waWfYydjw/WkEc5/ennCc9OVPn+TREYJxjo1DWlOpdvMoTMaiSx8AjE+9jEXwuXzWLjL3qbTLDi6ktPwxxXGQs8U3Irr5/M7ar7bmutYlTQ2ed6ghggKY+GkYuKZFNMtieoWviD0NZJ01fhMAb5gbdJWAM4p1gONjFeoyWColerWY0LMjTOXUAp3dPN8tNJCXJ//c8+I3jztzLAk5mNt4e8uVOFDvvw+5Ri8EtVZZgmhOTrLSuo/OqSS6VgrbK7WOcJCGAIwNtW19s81SglVsppCFxB/JYDVlfn/XzOiteTG9HHCwH7jJTeIGHi0vZYowFiLlsq0xIt5bSbDcpMaMnWCnR5Cj//oWPXtmR2wvTgnI8gqLb36wjoJGn9DZCM2o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: v4+k5MesDHa1MVSGi/UHPtmaF26L/lVN8GcJ71CBITc1I1MM0IDFIyBYytE453IGo7YT2EKkghBW/3Sk9E+bozL8K8Q/9nt64yNP1VUKTKWcNXGh0x3n6L54xVW44nCRVbatRJqN678ro8ZSzYt+2fRymUty+3o8u/17/PwxyEk9Ady2ePJuMOCoTjqlbeIOOmbEC/N28xw5dHvOPOovzSUgb9BAxSKqZmaCGbKEKN2DT/bRzqtS1Di8iAHNISKyT5Kia3S5FQ31jIr8lU9eM3naCerZx5CWbllDRJPUggXyPDUKaAxh4cXAaHrxbUuSXPbWSf2dHDC/0daQlqTmIDOHhAzikT+ON4WOwr19NAfx9YwHYZjSnq7QmKuypvDXn/4sFWZ036E16UhM22ZhF3yCJSsT3DjLdG8UtOX4toyIsdgCmi7p5QlaizYNgW+RH61ZTyCbLfrdr/vqHzBb7i9rreaXl+1cguCiLvEr5Go5xNdVG4uR7NyDFOlzkkVsbMfELRCU0p1mRPrIQdx6GL7zHrWHLhATraTb6GMS48zXasH4Dla6lHfNT/es/ZkxUzm5az8Zdjsb76SNDY6Qy0U9dVdWc5Wr/3tykSq/9BWFCam6QyHfXpzywRf5L/GutdWeL2qGZqKhTaUTXeGHEGF9kybhdDX9WoEPRubZZkhbyNiMckO0VrgM333uXg5hUIhn8B+PqVQen7cM0Yf1gM25kWnPI3xofo9GasPaYo/sS+suvzIvlhb2ApKpM6Rc4MCuXBM8KsXRBMlDEGL0r32OC2U3k4ymsoa2g5qKu7wKo3KGE6iz6Ya8AkYKuoW4nUzA9F4PaSeXvt2DyQABYPMdHHv0KPr9+b4R5tmZoteVrUkzO/IDIxlQAXE/0MOQs2aRjwCOMJIruq+MmWnpzVoZ5Wkmc8RWspNBAP+lJpmBZcIUeuUp0Z8vKzuqSteA2Cp+CP+6w/Vxi22Q1FuM16M5VQ0xW2fIukRt0PSMYAsj9qZln0bvBSCk4r32Tzd2Gh0o0RoulKFMNHy6Y2VjnRy43NW+4INplMPcCZXk7WjQgKv7YOEj3syOx9uYpUo5 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a6f39ca-831d-4584-1671-08d8c89cc4a6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:38:11.4626 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r1RSaXkF0zyFxShGIWuzhyAUNVmLQ3O5X3zrZzuMcrJieYM/HHT4wwktIQz2k01o9UKkfGFBJpMRNiO3jThp5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 This patch is to enable the 64-bit xen-swiotlb buffer. For Xen PVM DMA address, the 64-bit device will be able to allocate from 64-bit swiotlb buffer. Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/xen/swiotlb-xen.c | 117 ++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index e18cae693cdc..c9ab07809e32 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -108,27 +108,36 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr) unsigned long bfn = XEN_PFN_DOWN(dma_to_phys(dev, dma_addr)); unsigned long xen_pfn = bfn_to_local_pfn(bfn); phys_addr_t paddr = (phys_addr_t)xen_pfn << XEN_PAGE_SHIFT; + int i; /* If the address is outside our domain, it CAN * have the same virtual address as another address * in our domain. Therefore _only_ check address within our domain. */ - if (pfn_valid(PFN_DOWN(paddr))) { - return paddr >= virt_to_phys(xen_io_tlb_start[SWIOTLB_LO]) && - paddr < virt_to_phys(xen_io_tlb_end[SWIOTLB_LO]); - } + if (!pfn_valid(PFN_DOWN(paddr))) + return 0; + + for (i = 0; i < swiotlb_nr; i++) + if (paddr >= virt_to_phys(xen_io_tlb_start[i]) && + paddr < virt_to_phys(xen_io_tlb_end[i])) + return 1; + return 0; } static int -xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) +xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs, + enum swiotlb_t type) { int i, rc; int dma_bits; dma_addr_t dma_handle; phys_addr_t p = virt_to_phys(buf); - dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT; + if (type == SWIOTLB_HI) + dma_bits = max_dma_bits[SWIOTLB_HI]; + else + dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT; i = 0; do { @@ -139,7 +148,7 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) p + (i << IO_TLB_SHIFT), get_order(slabs << IO_TLB_SHIFT), dma_bits, &dma_handle); - } while (rc && dma_bits++ < max_dma_bits[SWIOTLB_LO]); + } while (rc && dma_bits++ < max_dma_bits[type]); if (rc) return rc; @@ -147,16 +156,17 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) } while (i < nslabs); return 0; } -static unsigned long xen_set_nslabs(unsigned long nr_tbl) + +static unsigned long xen_set_nslabs(unsigned long nr_tbl, enum swiotlb_t type) { if (!nr_tbl) { - xen_io_tlb_nslabs[SWIOTLB_LO] = (64 * 1024 * 1024 >> IO_TLB_SHIFT); - xen_io_tlb_nslabs[SWIOTLB_LO] = ALIGN(xen_io_tlb_nslabs[SWIOTLB_LO], + xen_io_tlb_nslabs[type] = (64 * 1024 * 1024 >> IO_TLB_SHIFT); + xen_io_tlb_nslabs[type] = ALIGN(xen_io_tlb_nslabs[type], IO_TLB_SEGSIZE); } else - xen_io_tlb_nslabs[SWIOTLB_LO] = nr_tbl; + xen_io_tlb_nslabs[type] = nr_tbl; - return xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + return xen_io_tlb_nslabs[type] << IO_TLB_SHIFT; } enum xen_swiotlb_err { @@ -180,23 +190,24 @@ static const char *xen_swiotlb_error(enum xen_swiotlb_err err) } return ""; } -int __ref xen_swiotlb_init(int verbose, bool early) + +static int xen_swiotlb_init_type(int verbose, bool early, enum swiotlb_t type) { unsigned long bytes, order; int rc = -ENOMEM; enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN; unsigned int repeat = 3; - xen_io_tlb_nslabs[SWIOTLB_LO] = swiotlb_nr_tbl(SWIOTLB_LO); + xen_io_tlb_nslabs[type] = swiotlb_nr_tbl(type); retry: - bytes = xen_set_nslabs(xen_io_tlb_nslabs[SWIOTLB_LO]); - order = get_order(xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + bytes = xen_set_nslabs(xen_io_tlb_nslabs[type], type); + order = get_order(xen_io_tlb_nslabs[type] << IO_TLB_SHIFT); /* * IO TLB memory already allocated. Just use it. */ - if (io_tlb_start[SWIOTLB_LO] != 0) { - xen_io_tlb_start[SWIOTLB_LO] = phys_to_virt(io_tlb_start[SWIOTLB_LO]); + if (io_tlb_start[type] != 0) { + xen_io_tlb_start[type] = phys_to_virt(io_tlb_start[type]); goto end; } @@ -204,81 +215,95 @@ int __ref xen_swiotlb_init(int verbose, bool early) * Get IO TLB memory from any location. */ if (early) { - xen_io_tlb_start[SWIOTLB_LO] = memblock_alloc(PAGE_ALIGN(bytes), + xen_io_tlb_start[type] = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (!xen_io_tlb_start[SWIOTLB_LO]) + if (!xen_io_tlb_start[type]) panic("%s: Failed to allocate %lu bytes align=0x%lx\n", __func__, PAGE_ALIGN(bytes), PAGE_SIZE); } else { #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - xen_io_tlb_start[SWIOTLB_LO] = (void *)xen_get_swiotlb_free_pages(order); - if (xen_io_tlb_start[SWIOTLB_LO]) + xen_io_tlb_start[type] = (void *)xen_get_swiotlb_free_pages(order); + if (xen_io_tlb_start[type]) break; order--; } if (order != get_order(bytes)) { pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n", (PAGE_SIZE << order) >> 20); - xen_io_tlb_nslabs[SWIOTLB_LO] = SLABS_PER_PAGE << order; - bytes = xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + xen_io_tlb_nslabs[type] = SLABS_PER_PAGE << order; + bytes = xen_io_tlb_nslabs[type] << IO_TLB_SHIFT; } } - if (!xen_io_tlb_start[SWIOTLB_LO]) { + if (!xen_io_tlb_start[type]) { m_ret = XEN_SWIOTLB_ENOMEM; goto error; } /* * And replace that memory with pages under 4GB. */ - rc = xen_swiotlb_fixup(xen_io_tlb_start[SWIOTLB_LO], + rc = xen_swiotlb_fixup(xen_io_tlb_start[type], bytes, - xen_io_tlb_nslabs[SWIOTLB_LO]); + xen_io_tlb_nslabs[type], + type); if (rc) { if (early) - memblock_free(__pa(xen_io_tlb_start[SWIOTLB_LO]), + memblock_free(__pa(xen_io_tlb_start[type]), PAGE_ALIGN(bytes)); else { - free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); - xen_io_tlb_start[SWIOTLB_LO] = NULL; + free_pages((unsigned long)xen_io_tlb_start[type], order); + xen_io_tlb_start[type] = NULL; } m_ret = XEN_SWIOTLB_EFIXUP; goto error; } if (early) { - if (swiotlb_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], - xen_io_tlb_nslabs[SWIOTLB_LO], - SWIOTLB_LO, verbose)) + if (swiotlb_init_with_tbl(xen_io_tlb_start[type], + xen_io_tlb_nslabs[type], + type, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc = 0; } else - rc = swiotlb_late_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], - xen_io_tlb_nslabs[SWIOTLB_LO], - SWIOTLB_LO); + rc = swiotlb_late_init_with_tbl(xen_io_tlb_start[type], + xen_io_tlb_nslabs[type], + type); end: - xen_io_tlb_end[SWIOTLB_LO] = xen_io_tlb_start[SWIOTLB_LO] + bytes; + xen_io_tlb_end[type] = xen_io_tlb_start[type] + bytes; if (!rc) - swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); + swiotlb_set_max_segment(PAGE_SIZE, type); return rc; error: if (repeat--) { - xen_io_tlb_nslabs[SWIOTLB_LO] = max(1024UL, /* Min is 2MB */ - (xen_io_tlb_nslabs[SWIOTLB_LO] >> 1)); + xen_io_tlb_nslabs[type] = max(1024UL, /* Min is 2MB */ + (xen_io_tlb_nslabs[type] >> 1)); pr_info("Lowering to %luMB\n", - (xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT) >> 20); + (xen_io_tlb_nslabs[type] << IO_TLB_SHIFT) >> 20); goto retry; } pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc); if (early) panic("%s (rc:%d)", xen_swiotlb_error(m_ret), rc); else - free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); + free_pages((unsigned long)xen_io_tlb_start[type], order); return rc; } +int __ref xen_swiotlb_init(int verbose, bool early) +{ + int i, rc; + + for (i = 0; i < swiotlb_nr; i++) { + rc = xen_swiotlb_init_type(verbose, early, i); + if (rc) + return rc; + } + + return 0; +} + static void * xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags, @@ -566,7 +591,13 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, static int xen_swiotlb_dma_supported(struct device *hwdev, u64 mask) { - return xen_virt_to_bus(hwdev, xen_io_tlb_end[SWIOTLB_LO] - 1) <= mask; + int i; + + for (i = 0; i < swiotlb_nr; i++) + if (xen_virt_to_bus(hwdev, xen_io_tlb_end[i] - 1) <= mask) + return true; + + return false; } const struct dma_map_ops xen_swiotlb_dma_ops = {