From patchwork Fri Nov 26 15:40:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12641013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B09C3C433F5 for ; Fri, 26 Nov 2021 15:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JxnQ4R7k14rFVmAQ6kbgLC3oxs1dp5PQwug8DjJq3qI=; b=PRUKHKLpsnM6yG kmAlPezLh+xmBY9b1xXoCpb3eKlvHp1e/rWH8vvtsYnjcgxKU5jCav3VxfNgpWgcB8UdpzyrTrVLN o0JJfaYzEIW4Us+/50Vd5Ya6a8kn6L8L0koPRuaMwV81NU6VlBg0LfHLDXvxNrudJdeuhtETFVXoX u2Ec9SFZrGTxPxLFiNh3QYRJd2Iw4eg7RCWbr+SSU/zj00tTz0mpHGKIkvx6i8JJLDchZiBEx32jG CvvCE+Muh0/9j1UavXodLEDlZtjxlI88HLsHaTfdmHVVIuXyV1uvmGZE4tkaehrGi62JhuWEF4D7a cjHVcBhfaebrTWHnAFNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLN-00Axub-2t; Fri, 26 Nov 2021 15:40:57 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLK-00AxtA-C5; Fri, 26 Nov 2021 15:40:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637941253; x=1669477253; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Tjwhc9vT9WwipkcblO9vU5OVOm5KngnEVoNyzcLRv7Q=; b=AES9DsQr9zw1KjxdrVbvv/20tZZyBgwwVAc39klhyhTjSU0AkaKgmYht gpIYfc0ugx5sua0rL/OdhkDeHI+/n4SOg8kmPADelCPMg0A2qJQsbtj5q xHNyzYagkchgd8+uPFZw+ZJiOuq/l6Ksg/cEZRtLRAo67Q6Q+02Uz7BxD lWDZ4lTcOB4Jz1dDj7Oi2SUZnfdxIqTxEgh99FW3ZN3wBr2ZLGxMa+IQD TnSQGCnaOw5DAYguNcmozSmS+qK6aC0ZZGxQwtaNzK4OIgqLBqMhnoxZ6 kHTyGC5CVRsWyePyMJmW3fqFwuyRR3KsXdewFOpJ+QyIW5QsYv2+a/VRK w==; X-IronPort-AV: E=Sophos;i="5.87,266,1631548800"; d="scan'208";a="191541491" Received: from mail-co1nam11lp2171.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.171]) by ob1.hgst.iphmx.com with ESMTP; 26 Nov 2021 23:40:52 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LL31VKvtjRRCjN7coymTCBuNZNU3Y0LOd5NZa67IX+vHwQbHl/L8iZsMxZQEufyhIuVM+gOgkYiuHduy4cYKtQyPG13H4G5UjboZaZU924MloLqIphYLu/otqUHWacrR3Prknaf+YBCfrJxfk/SR8vg9BOtiFyI11ie87uYaO4sf6Npa5IIBmzKhxN/72v1BTTHYlpdiyJrfN170qGyi0yZcbKPmvdaG4NKMsFcEDHxivy93o+8tBITFWduQKvSw0/p9hf77L1qLm47lqKLJFOg6RzGJl083AJ2syg8USsErZtxyEhvBAQMZFVdiySTc3NsfBmDKjSf6+FUj/UTYBw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jd9LQ6X6JNI7eUzbXun1o5KucUYoZhcWgu5E0Vf4qJI=; b=ADvcDtYVA4LtpzAO/fHmN/KKK6GOilyIWotg5H9Up4QsnWrF6r2jKD1ZQYJS04wutSX/sCghW9RJ22nnvGf9r+DxcELlNlM+NXpM0DanIseN8Odv3BhcdzhlWDKl3pNCNKNTfE299PxHSQ+MYbF/KPZsf35MoFAQGFH9y2kdUAUJM5v4fSm1I9OjQp96GwQQy10imfJ2vQFgB2PAUhdd1MGAsxg9w3eSTIhUpqFGJRu505o/Mmrwy7jA3TvjJnzg5dv9kUhLyOroV+Zj3iXzbW0I2rXUo3IpzEdWwoxoLg6GHWHrnXXEEI/oFWbYr4jnKtgNe3K0jOCpvUuBhMQELA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jd9LQ6X6JNI7eUzbXun1o5KucUYoZhcWgu5E0Vf4qJI=; b=oeHrddYFkRoVgHVwBZN2DlqBNKLg7TjGp0mKJVFYaSxxHwKl1+4udTTHrWu4PIr9Cm27rbp70C1HS+zDu6rxx2uuIt25VtgpP90vbgRICb3o70g9BKhtl0ga2q+zfPj7Rc6HJBWxH7FSzmDz4QgUzHrTnSXkBC/0aCmreSmXl3M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8330.namprd04.prod.outlook.com (2603:10b6:303:135::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19; Fri, 26 Nov 2021 15:40:53 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4734.023; Fri, 26 Nov 2021 15:40:52 +0000 From: Anup Patel To: Paolo Bonzini , Shuah Khan , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel Subject: [PATCH 1/4] RISC-V: KVM: Forward SBI experimental and vendor extensions Date: Fri, 26 Nov 2021 21:10:17 +0530 Message-Id: <20211126154020.342924-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126154020.342924-1-anup.patel@wdc.com> References: <20211126154020.342924-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.118.153) by MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.20 via Frontend Transport; Fri, 26 Nov 2021 15:40:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd523a92-3274-4070-64b6-08d9b0f320c3 X-MS-TrafficTypeDiagnostic: CO6PR04MB8330: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dY+pjsUR7o1dbDgZtIvPy+0O0Bj16wH9BdvG3B+2mnv1hcPZm6WZiAJZwJPF1w2YIjLnH/DHa7P+n+Mv/vnwmt/l33UUznv0MUWY++0Eqf4sajJeljO3ejCYyKXnhVm2mLWVhsHuM70xWWa4LIG4fUPtdUBvqSrwzw7g+Qineetv1Uuf/9dBolVR3b/uBLH8WNXXfkp4bDv8RbU7+O6suz96OzbDJVYV9e+cJlR4I/iOJQzJTktvuoxPS+craliTf4qUV/s7Sf03g9xBZRLvBiWdIwZhDU3zUxyng2LT57hhuTaxB524JpjzzvazYqn/FRubPKleMlnotOJo4ARB7QHMiKiwgi8bNDAtfaYKCCuWzdcYxWweFigYVyyandXPSatmw4Um01SuhGi6+6AUm3/amQoFOLs+523eI8OCg9cgodYvt6d1AJBrHjpvbQ/NobnwI6AQtDd7sqr80S6fGZdYp0LWE0o4NHIQh9QgK+nQC0N5faMVG3UMh304/y1WqlwWYdZdCh0u/yW6sIgvt+yVTmC/aOdiQwbQRTDdyVqk7VgGmzeZCMfyUOHFR2qm9VBKqiFS9vM6GK/DFdQFykxHs7yyMfeYHFUq69Ogc9CLXMY0BwLECCOKzWIARuKznsFb/mJeCzSZK2att31h0GLkpPD3iosmB43BUo+VvCI16fnx1SclWjx3adywsQoJo4V/as67qXi+k3A1K3OAVA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(1076003)(54906003)(66946007)(110136005)(38350700002)(82960400001)(26005)(66556008)(186003)(44832011)(316002)(6666004)(86362001)(7696005)(956004)(2616005)(7416002)(52116002)(508600001)(2906002)(5660300002)(36756003)(55016003)(8886007)(38100700002)(66476007)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4wYXltuhYpUL6ZAYGznhd6K4MDYnbBAbJX6xoOQSJfgCF9zx5DjiN9YVxWtfoBOG3EHAsy57RJq+wqQyOae/k8tDEdXfvX0/F74DBDBWyXiBrNUGzQIcN4FeL2NcFZu/qVALusxbxT+Osy/XJcUN6Oj81QBFkcv49OPStrFFP2Vl+Xj2pedHacL3w8rMPRdppnJSXwQUpe0A9wRgBuCAcFFvY1Y5fKrPfcTU7D66nYnjX4VuVwcPXKMBeM6Mln8GCM5e5gkEa0tTHn4R6K8zaMN/dtMEXT3a99HYhohdtxt4m0K5hD9NBXojXVvhV9AtlJE27gL2/sjifAYky1w8rRljiqzyPzFVz1Be8+eOE21ONkX7hUTePPxQb05qVCDf/7pUwswEYhho/xzB1yVcwJs0b7traEcjYP4p2zER3fCptJLUBQUudGscoRWY8m6TXiR8CChTFuZRkeXUtvysNoHzwotzC2667LrdSN++dBtoNeHeiwONQh4163Ms7zlYZ/VQO8KdoQ4Hckbr9hTxnR1w3lneuLofU86VQA/FJyy5JY00O8xpe9smgXMKmDV6Y4F0ZLCHBGbqCSETRYgArcQEY09Zd8qq/76WB02+IE+UjWwJxHrpJbWmK00NDBzQQ75KA19qeR5IUSdig8BTA6nW25CL9gh2UE0jvV78qGcyiOXnJ+EE+H1aQIJbfQcKgSJuowTy7BbnPZ6HSJIbL2tlCmurPKGsleqJeAWZVXpXUqYrIcafLS5/+LRCgo6B008YdPrBDUK4JezMbcr/g0sKgysjFzohcRVHswXtIHw1Mkml83h2XS90qO/Uag2QeSYbFInYOn9p7jzWMT7QRDlNWyv/cQ0MYm+xq9mUnQBxrJxu0LvyQoCDE0MnQAw9Wggrn3kLpxg7u+IaIrk4ubCjPFQrZuGqDKFEKvkcMK5isRP4rsmsH7oH9seeBgpf6I/O7rq3BJA8rtQ8/swhsH8D5novvZQxSa++cr2bbhlMrNO6+HC2/r37jInaazuF3jI5QqQksesjuXHvbdBUPKi3TjWIBPl0npy9CqMXCFaadx79VQmbxbRnfhpt5GqdtYuVYIl9NihVPGXMrjZbbbwW49LHWfNF96DZ1sTMWGVoux9EhXdPElFAAhztaLJYZbwuPZs29PNqsFoPQwLkivnrwF/dl65Gx9cd6HCggj+9N9sr8PQK0x1uDndy9U9sf8YC1wXZgwNCr3voNDyOHA5MZI3XcfGBpisbnvTOkD4dmeH1Gnwx8nI8piCnxP76N9/4xG8+BqfQjHsPJ4K7WNWVbCtzQDv/kPVvLPVO9OUyrzy95IVDn7fplrQlIpkGjEHVGBhOZhyQQzIKiwzFM4nq+7nEYphapITbHsVHZfYBd96hFaehntMYPSL0+FFvwVRX3y873dlt8d/ijwTaVmroGPL7oGhHcS1KSPZ9VkeejSonnjnl7kV7iSDDhYcBxoHNGPN6/FtpnNdlZGfWxLDw2w8P2zC5CwI8S3TF76XtdzBtZXx/bzdd3G1JwrH8u7lsgWt8u9N9yHjQCrDxYbWHZuPRsMG5cJFIa1Vv9HBb5sVJOzTuWho/3dnbf4WCFuzpmdAlY+4Skxw3z6X+JrCRwgR/AxOuJEgvqwYd4uA= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd523a92-3274-4070-64b6-08d9b0f320c3 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2021 15:40:52.7244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pOEDVfuwnbwwDjBuapZT1Qh8DMcGm7XGub2+ydbM+fJbFQvwop2e9M0JEDlfBl/XGR4BKXJU6K3N9oJiDaq3Kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_074054_450096_3038D3D5 X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The SBI experimental extension space is for temporary (or experimental) stuff whereas SBI vendor extension space is for hardware vendor specific stuff. Both these SBI extension spaces won't be standardized by the SBI specification so let's blindly forward such SBI calls to the userspace. Signed-off-by: Anup Patel --- arch/riscv/kvm/vcpu_sbi.c | 4 ++++ arch/riscv/kvm/vcpu_sbi_base.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index f62d25bc9733..78aa3db76225 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -46,6 +46,8 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; static const struct kvm_vcpu_sbi_extension *sbi_ext[] = { &vcpu_sbi_ext_v01, @@ -54,6 +56,8 @@ static const struct kvm_vcpu_sbi_extension *sbi_ext[] = { &vcpu_sbi_ext_ipi, &vcpu_sbi_ext_rfence, &vcpu_sbi_ext_hsm, + &vcpu_sbi_ext_experimental, + &vcpu_sbi_ext_vendor, }; void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run) diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c index 641015549d12..2819c325f471 100644 --- a/arch/riscv/kvm/vcpu_sbi_base.c +++ b/arch/riscv/kvm/vcpu_sbi_base.c @@ -68,3 +68,30 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base = { .extid_end = SBI_EXT_BASE, .handler = kvm_sbi_ext_base_handler, }; + +static int kvm_sbi_ext_expevend_handler(struct kvm_vcpu *vcpu, + struct kvm_run *run, + unsigned long *out_val, + struct kvm_cpu_trap *utrap, + bool *exit) +{ + /* + * Both SBI experimental and vendor extensions are + * unconditionally forwarded to userspace. + */ + kvm_riscv_vcpu_sbi_forward(vcpu, run); + *exit = true; + return 0; +} + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental = { + .extid_start = SBI_EXT_EXPERIMENTAL_START, + .extid_end = SBI_EXT_EXPERIMENTAL_END, + .handler = kvm_sbi_ext_expevend_handler, +}; + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor = { + .extid_start = SBI_EXT_VENDOR_START, + .extid_end = SBI_EXT_VENDOR_END, + .handler = kvm_sbi_ext_expevend_handler, +}; From patchwork Fri Nov 26 15:40:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12641009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A104C433F5 for ; Fri, 26 Nov 2021 15:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=62113YEwwQhKjhTs8uV3y4CcI3gAOh9FdZPjX1fZ+T4=; b=exCu+UzSqopPj5 QsPiyLZS7kjTJhAnvTJQ1BmhL4uHQbqMbtXed0304X0buRzytQ6E0KH7HZ1HU1mXJcYHClh7FX4Hu hXracinle6Pb5UXTG+kSyItPcTlYYuRqTmonJ+cePqkzb2QtWRpDTnHR4nKBd/6t+EJmqQbVjEYva FMbtQaMBNi9s5l4Me7Sb/bVGPljEUVuo0I/3V81iLOCVeZtY69u2QqKzvvxSNUiTDXV81Z7FoJ2W8 Fr2fiucio2xGWfP6avvGOz6F1U+mfoD1xktl6fmeadbiWC27YD3hLYChhJphm34FFMUieEdPkeB2l D0cOhJViAaQbaxcGDwMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLR-00Axw6-6e; Fri, 26 Nov 2021 15:41:01 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLO-00AxtA-EN; Fri, 26 Nov 2021 15:40:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637941257; x=1669477257; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=UvMhmajLI2xKJt61vOJnJU10E+9HbwYJfu96S4+MsQA=; b=CoEky+EXlBSO6nQry/+qi4P59BG0v90Co5BGWCzzhlyf/bEwJz8SBPsY 9X92yU108KFeI9vFniFcgALH2VtR2jkzxjn1JhFBrs4IfNcTA7hFYwjRu 9U015tmEEtc9Cr7wWRowBl/LjhssPbs6c9uMlUW0WQ0Gi1ULTQqbvdqJp 5WnsLyC18doua46cm00ECxQ71XeYBvYLnOL+iONRzJm6WICShdOVL27uC 8BPID67cyzsIzSUHRIcn6KAYjXkbqlCtBMqnUPwGROd/MdMSI4nSOXMyJ sH+DPSp7D7e4r54M3UiFf2Aanigbc59SMVXrr5deKxB1mvFIAX76vmqk6 w==; X-IronPort-AV: E=Sophos;i="5.87,266,1631548800"; d="scan'208";a="191541507" Received: from mail-mw2nam08lp2172.outbound.protection.outlook.com (HELO NAM04-MW2-obe.outbound.protection.outlook.com) ([104.47.73.172]) by ob1.hgst.iphmx.com with ESMTP; 26 Nov 2021 23:40:57 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n23agR7kwNMbZJFu2UYNmNRUhnR28OC2GnTmBljOd1rdO2KrdbMx7NG+rKgCzcGEnqbajSQfpMOnp8gxh04F36Nm6TK9Ma6pOj27fLmFeqPdPF+zJRj2Tx/dNj6H3BOkgHGzdP8dI5p9QfiS7fV+wLa36SBcCMK66uUX6exTvfcno1UJr1xPjpVBppj2vQXCGzWxb7Voxq2ERAVp8Ih46OOnpvGBSalW5QeOMPFfhIw3I35+zYV2nOAr4l20/MI+8sOwWsaO7G8LUWeGKIX10O8wDG60t5Wd89BjCgARMDO+4mB4CJEHuyQkGXfQZdVqdz0hGmkzVsiUwV0aoCfgVg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Kd9MbxmTph6FKRePFQlLrz8Xb9yNl9hX8XE8rQyPpO4=; b=btPMDwVH18pGNK41yLkKck1BLf60s4+Pb3cmSrGa2HebNV3xZmowel12ISUmE+BAeWBy3qDO4Bsnb6vUU0qWNWk6ePFaQMqtRCkbhQ+viBCAjiMV9TJZ2f2tm8zbVtWOGwQGNaQblrIJ/nJydRLS1tqPFdquLoHZCMsv4qE0jGEgYxt7v3l7DJgQFD0Pg9kId4219S8O2Xamg+GNx6bxNZC6FVuVWD0PPvMMuclexgc+gPWBZ0K4BTJga5w9u4iXHXrlXpDbVS+WuJP7LSGO9BtaUzx7LwWeryjqmBmiTsioybkSpeBj0IMIKBwHj2/nlEKJISqfDF8D5CiLFv3rRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Kd9MbxmTph6FKRePFQlLrz8Xb9yNl9hX8XE8rQyPpO4=; b=lbXdm6MVHaEgChlVm+SOm371P+IuoYUUz81XwVoxZvYmOHvlSTssUShDWa8/wS0wOQqVHcUSI8EhJKp3UVpqKqICfk43NosDYxd/VhWXLajc6Zj7DvFk6q9AgSLEEWcX5PdPEwybkUhQH5Rx9nXYSfpi//wEQZL21v80r5M7KUk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8330.namprd04.prod.outlook.com (2603:10b6:303:135::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19; Fri, 26 Nov 2021 15:40:57 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4734.023; Fri, 26 Nov 2021 15:40:57 +0000 From: Anup Patel To: Paolo Bonzini , Shuah Khan , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel Subject: [PATCH 2/4] RISC-V: KVM: Add VM capability to allow userspace get GPA size Date: Fri, 26 Nov 2021 21:10:18 +0530 Message-Id: <20211126154020.342924-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126154020.342924-1-anup.patel@wdc.com> References: <20211126154020.342924-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.118.153) by MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.20 via Frontend Transport; Fri, 26 Nov 2021 15:40:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 095abe3d-d703-41dc-5f2f-08d9b0f3235a X-MS-TrafficTypeDiagnostic: CO6PR04MB8330: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sQyrjq01RPcqLxDt23o1AejKQcfAdPUcSz1nBzUlqm0WCIbYDXMZ1TWsyfyPDPpjn5RTs50rN+1gCMTMOk0p6azveTKIWMoy5IgbwK7ndwnDULVaMv7iulMRhMocuCdgDoFCWfhoMxq3W+NUE0milNoQG0rbN/kgPm3gc0NKk+nORTYfsGeyl0bJStIhdX2/8UyzY3G+suLlovNv1Z9yJhECCon7VqhtnuLicwek+kBcplKnYrUq2ZRYnVMqFfohY8moTWTazA2oIlf9eQ8pqj0TbShXuECTAzkAIZUBedZV56OPIkFdrbU5XPQKr8/XKmfkyldyjloSG25GxR2voQzDVejm51lYfuxDFBqyWFqG/CUVEOeYisH75g1jMWkKMPzGve+1YuBx0DtgOdR2QEGQzG+qSB5d7rOncpICH8eYhqVKy0vR6fsTZxulaDz4oQvGofoKJ9GML2vN1Lj6v6VVoZnzjr8dS0+q1V14o3mOzxkEzjIFS7DMSUZVahHMQ3qPlY0xvswt1fIdb/S2U6/gzG5LR4VKpfA4oWOdeIFeCGH0tUjzwp0APQCdH3S9+CTxloOOg4+P4/HHCJmo9Vw5QgCjGSNWX9jB2iWlBodAjbDUO+6CES9Pl6aB9VRvVzKZzSMsBpCjUfU/iM5EZLeo3ZgHA2ezW4KZyYvQEGsNGbZV/ZK/gU4FP/wSohWuHU0/13dssamg9WZA5Pw+fg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(1076003)(54906003)(66946007)(110136005)(38350700002)(82960400001)(26005)(66556008)(186003)(44832011)(83380400001)(316002)(6666004)(86362001)(7696005)(956004)(2616005)(7416002)(52116002)(508600001)(2906002)(5660300002)(36756003)(55016003)(8886007)(38100700002)(66476007)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2iVhKPFs4g3NfSwX5xUciiTT7T8KPLb8Zo8TRPaCZ1oAuI0QKLLyiIESo/0po01nXff0jX+eECAwyc56Jtj3AwFNeuLsGkOnGDZv4LIieNrpkUOPHZBkE4028F8LjIwzPnZ+BWGNMfi1swzU9tJdSI1vvF+XHw0FSTDe4yz9zImbQoqRFBDVACEY6z4pS24CLICm5V9tDj0aBdsLwUZkc2w28EyrlnyQzLUfwruDxuDxDzxbivn4dbSnxuF+P2EJXPzDl3+DjMQfuOSWQfEINNjytRSV1E7M1pth8n8WRgDQ8sp2lB6zeyK830/xR1nK5UY5fJcU9L5X7npGe4HmqDjSJsB+wsOpOjHqNTuiLsaiOSfe9UMfbBcpGv29pF0ioeNEPavv+QrJ9E05uEKCcfBrV0ChJFlnKi/WqTywDY6QMOHs2nMd3CXAWejJ7e5FMBw8kk20ZokOgDHVrKH56NrHwTbFadTUyskZ8ffcziPvN2p83dj63wsq1DkF7pM7wzomx3MDrMctObwWvNlkaXb5hyb4XurKsaU/ztwuEzg66IwpidupWHOIh5mMV4KjqfBGlZVZRqJ98U3omSz2dg5Mn40xxTb+qaYGOtjibPD9pUHulbCayLnuRkNijS5injTyFfzxvvjDPmVuzgtw0r5egxCvG27iHXvJBOsUJXaMO8kgFV6unRgcdUSkqoQ0C82XFh0V1r3TZPtB94/pAra+UFDTVj48/hOwZ3hJHoEwScpLkiD+yTkjY9oRbvthhDFMJBnB4DGWW1LMEaKNmE9LlaNIhLDlOYsQk7bXQeZ56dJTwTYho+yU6g/t7BMnVs2x6CjnSXDrGJNt5MN8FXSfZQOsQD7hTaQESZbdKfafnWGKFEYhMRATSg1JQR9qzpPy5zKH/nt6Z07RnnukB8fzx1l980sLMP7Fk1M9G2Zaw27m021KjIf+wB0+9tXgSsCZfomcfRMcuxO5GVOgQFnzM7nMuM/kJ4DEN3Eqc0xpHwekcnaDsLVrdWf5ungveuvkLaKZyCfSofu7r8jbGAQ651fISP4nyOJAv79Zox1udCBYDHG1pilg0wb3BP7TIwKfFU3iQvVRGbtM6KrH/b8g9HBp9N49Ft2w50uprmLrA18IjCxJ6hYhIRbktmPYLlIhR0+VBxIuDr1VN8gAlXNwTFZ+BXjpIeKuvJLW5qOhWB/Dc2+PrYfn0Ej5cK6Z/l9Hl97WShf04Y/T2HPpq+nXYIK4Z//c5R/pafjymQ3wSt24cMfgY75H8HmkDthvF5pfn4tJNVLMT9vYXtrxunVeq2XyAfWza49H6GppA0tjd2ODd64rAq5Bmtt+vv2ymowGtm7vtblbJHdeI5+iittchwjUI6f7x29mJtFCuyoEfQUNRfJIn/zdFkP1r5daDyBq62b+LcO7zu9reYPsUbZPKE2HfLZz8g4oOyrvDMrsNCKyAdYJIxlw2C49Rh3Lc7itc6sV6q3Qskf87bHKqjen28M4havhNqxtwLS0rJKPZL3Df1aCD8d5A/VHZ4EDB4oL98+OQfghoa0QHs1x7tnAXVllWAZqygxOkCGFNxr7X0D9shXYAc4v8T1t9hCv/3MkmcsyyjtDqUS9HWeZswZlR/64tq0p+sR4E4TPriw= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 095abe3d-d703-41dc-5f2f-08d9b0f3235a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2021 15:40:56.9677 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: x0QGzurF1kkvDAI3JxTYM1eqRQN9S9B2+ddKcWrbd/cD0fVt+6VpHJm1BKabQ1Uya/+vr0DYY1uT+H8W9aDkGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_074058_520852_06A183EF X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The GPA size supported for a RISC-V Guest/VM is based on the MMU mode used by G-stage translation. The KVM RISC-V will detect and use the best possible MMU mode for the G-stage in kvm_arch_init(). We add a RISC-V specific VM capability KVM_CAP_RISCV_VM_GPA_SIZE which can be used by KVM userspace to get guest physical address (GPA) size (i.e. number of GPA bits) supported for a Guest/VM. Signed-off-by: Anup Patel --- arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/kvm/mmu.c | 5 +++++ arch/riscv/kvm/vm.c | 3 +++ include/uapi/linux/kvm.h | 1 + 4 files changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 37589b953bcb..ae5d238607fe 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -221,6 +221,7 @@ void kvm_riscv_stage2_free_pgd(struct kvm *kvm); void kvm_riscv_stage2_update_hgatp(struct kvm_vcpu *vcpu); void kvm_riscv_stage2_mode_detect(void); unsigned long kvm_riscv_stage2_mode(void); +int kvm_riscv_stage2_gpa_size(void); void kvm_riscv_stage2_vmid_detect(void); unsigned long kvm_riscv_stage2_vmid_bits(void); diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 9ffd0255af43..9b6d6465094f 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -760,3 +760,8 @@ unsigned long kvm_riscv_stage2_mode(void) { return stage2_mode >> HGATP_MODE_SHIFT; } + +int kvm_riscv_stage2_gpa_size(void) +{ + return stage2_gpa_bits; +} diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index fb18af34a4b5..ae97f6929897 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -82,6 +82,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_NR_MEMSLOTS: r = KVM_USER_MEM_SLOTS; break; + case KVM_CAP_RISCV_VM_GPA_SIZE: + r = kvm_riscv_stage2_gpa_size(); + break; default: r = 0; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 1daa45268de2..dac98df3101d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1131,6 +1131,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204 #define KVM_CAP_ARM_MTE 205 #define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206 +#define KVM_CAP_RISCV_VM_GPA_SIZE 207 #ifdef KVM_CAP_IRQ_ROUTING From patchwork Fri Nov 26 15:40:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12641011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 477EEC433EF for ; Fri, 26 Nov 2021 15:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KJVeixz61HkHf3t+DI55nPTdRRyXye7r3+aPNjC91JY=; b=3YKb4VJC1FFO5o LO7ONlcGv6ew4XRB9Sq8sA/4aOHmZDWNIHekd6dF73OMKr4KFRPr+Qj/hWicMhZwUhJpqPgxU+Muu 4Ov56AWMd71zMwDDekfBn7/4K0b6nQ07DGOLMIqG6m5IrXrA1Rnsr+oLAw0HMhyB1T5fMl6Pc4dj9 eWaxFxodDp/oaWVFlHl/hYa068Fa0hVLvnnxQbUEGumdrHpOXjjWcGLHZi5FHGxSBOzORwzqiQT/H ASMry6daNtUpl7c6V5bE7X78bMC0Sok4pZ8/w4sdN+xg6ynmLdIq9n+HbgFlEb8tgsNMd2X+AorUx fnhZTwpXRmbGGfh0arvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLV-00AxxX-Bj; Fri, 26 Nov 2021 15:41:05 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLS-00AxtA-PZ; Fri, 26 Nov 2021 15:41:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637941261; x=1669477261; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Yyd1xhd5UFPVScLX53tcVgS6s7csjjr8e3ZJXvcaHIY=; b=R9OXGFPNYYQOKHU3PW94RCjfC3qllR576w1XzySZ4IYzByGNP55ZiSoE IcxZ+RmE9lJfs+oeOvT8h0MYmbVIxIVy6KYd9hWEqx3aG0zCT//Zvnp2d VGQ2Eg6fIYtwKRFXB6XCfks/NPDvhdLwkxTLZB0LpeJxH6mnQe3A8z6UW T+FpVBVqHgGGE0Q0BUWzkhJtZ6pftLdevhH77s2wuc9RqonRRVfwqXRL5 QmWyf/+GSElGczA+rI7X08cQQYM+mPvEo0Tblrnp3gmwPQdYnc2Ho5dgS 6lBOzMPNhkQNs6FutbFpQ1YT9X7sWPQO2iJyJn6ILi22lgwWJL64Bb+9p w==; X-IronPort-AV: E=Sophos;i="5.87,266,1631548800"; d="scan'208";a="191541527" Received: from mail-mw2nam08lp2168.outbound.protection.outlook.com (HELO NAM04-MW2-obe.outbound.protection.outlook.com) ([104.47.73.168]) by ob1.hgst.iphmx.com with ESMTP; 26 Nov 2021 23:41:01 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmF2M2JlvW4VmgZz7hbsF+fV4y8cCUz4WqijsGteyXo0bdKi9VqAGNHvwzqGqd1xsd08EbRt/VY5TTdpH9CQnZpXq2iO5mWC0HpQtKvaU0v21yYE8tCv3luBbRP8XuziFXdncrBZ6jMP1LITyGwN/A9/+LjUNs/7BiROoV55Hi8dM8Cc/nvYSnXQhVPfR1D/e1wsqKrsVdMuDbHM1Nw1evELdaNhOAEyetJKo/97lqiNtlahQF5xwHipQ+JmcCT+KjiUmgYxXOzrNT2jOAdzLCyklVZB6UJsoaiNyJAySTDxCBVrSOFcfBWp+RGiUBz/gyk8lx+DKN3AyRxc52Ek5Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fx1+8DqUGGhGvD1mIGY99MgbH1pE/0dGb3IDvhqS54w=; b=Q63FZ2tEE5uq8aOtjGSOOJpP9FsdM0ZD2kpOP3jpq360d2uSuZlYsNCXbAKxlQxqXpp1GxjVzfkfpem9mysXEG89NBoY/LZkIhS3s6BMdWeG3Pd3MkRHlyyPLIC+5j0p53J1gSXGaYzq6lvb4KKXbprlu0DO+SEsn8lgaemRxGnp/TepbNY+w9l6ivOcqcamf6xVmbm3pk1/URuedzcswqvtEHKlo2KvCKiOXSvt2UbqHncknLDQcCBprCCCremwtdLCkWl2IS308zmD53UfnU1ZU/gAM07xDZkok7GUiAhkoBERcutsciAGUHo7Ow0wtg43ULwr75C0ik7txWqJvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fx1+8DqUGGhGvD1mIGY99MgbH1pE/0dGb3IDvhqS54w=; b=xGSPKPMfhLIK0S7l47xDbrj3upFVDUdS04ywu0/WDtgb/ic0QGiSQHpjj7PUrCEY4VVV4e7sdfxJuqHeqITjwGqAwVhF5hPOIo8ZOgMWrZ2i7470pb0T/hxaI9/6bFRZZnXxapS5iG5fpndg8C0A/sWQ1k1JTM73nEiG2FAK22w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8330.namprd04.prod.outlook.com (2603:10b6:303:135::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19; Fri, 26 Nov 2021 15:41:01 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4734.023; Fri, 26 Nov 2021 15:41:01 +0000 From: Anup Patel To: Paolo Bonzini , Shuah Khan , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel Subject: [PATCH 3/4] KVM: selftests: Add EXTRA_CFLAGS in top-level Makefile Date: Fri, 26 Nov 2021 21:10:19 +0530 Message-Id: <20211126154020.342924-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126154020.342924-1-anup.patel@wdc.com> References: <20211126154020.342924-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.118.153) by MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.20 via Frontend Transport; Fri, 26 Nov 2021 15:40:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87cf417a-8310-4d53-1c96-08d9b0f325fe X-MS-TrafficTypeDiagnostic: CO6PR04MB8330: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:913; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eSOjavi9CgSXDSRu5EG0czTb1ulhajkB/pdNfWhiRhSR2IH6+W+XD/1jviluL+9Bi27YbN1CMSWN1ndinCoDZe0jMQHoW57CUrsGVgX1hz8nIyuIb/WdqFc/8aebrrCmgy3p+D4ureUA0EGTT1Cz4yHDeU3BvDT/OVOEnvkVbnJEBJ9wiRAvXp8h5cfMF/Cy4WqH4WXaO5FQzTPISbd9PRxzKP+fzUKzxfyvN4xR7aYroLNVSU5XOaZtQ3FPif11fTkTA2Oz3i4jWo4tegYP1b9puZbJT2wIsZ4giw9DdnqkfWt/ZqNl2Oik+u+MdaUXFAcCO2Uj/XoQnz887qLFlJGV5KgrilvcI07C3lnXQ6g0LtxzEljYVzAIwqxute7Gh8MmiUKkrWJd2WiU2yPldQsqlwr92+heK+ZxfyOlLyPODsqIpniNfAliCUTDUhO34+nGL/WEeXDeRBLeoY9bF+SquVQzQoFfF85+LwBDhPqOtC8J/AabX0dNR8gKdhsPPZ/QhJyevqifkA5sBij+fmr4K3mTgKcM6XRlNmtCPsNjA81hnl4ljgTDRYUKh6L9/sHHbCUMKUG7GELxVSlkhLvsakpxWrGjKIuGPpJtv80HJb74lNHgA5eOPlM3TvqT3jO33ysbKHY7nOFmbrf7gk23TzzlOyhpPpXnOnHn0nr6jnluijk/FV5xR3MDAXyU8aVa/L2zqdysKH3pUmLoMw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(1076003)(54906003)(66946007)(110136005)(38350700002)(82960400001)(26005)(66556008)(186003)(44832011)(83380400001)(316002)(6666004)(4744005)(86362001)(7696005)(956004)(2616005)(7416002)(52116002)(508600001)(2906002)(5660300002)(36756003)(55016003)(8886007)(38100700002)(66476007)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gVML5QgT5Om0z7oAlYXmNAFA6UMHL5mKL4kWT6/oK8mG3SAZpI+2Dpfjg2L9fn4IL51J57ZVH6ygF7WXNMKiTDMgDCXznSwk3v4IrB64LhUWGtQ193OrpFO5FPZbw1BH9FX5WPp1sp9Z/ZlIqaQkIHwTTY17zYcbD6Q4Woj1nBR66K7dpaKwl8cA2fud7E3D9azGlJFl2W/rDBqlXPu9QoZh2t0qcv1D6Gh4Wp3L7ZtRuvY5kybqdQzz7C9GSMDMU9uBeIgIzmplTOcw7u6Ubwpvp5nsL94FrBXqkuX08GEYdFqJe/QdxnValeqiwTRjijVq/rIo3BXrIYk0clUT8QEv+V041/IBfdZPRVC4o8UaEAAiAr9EPFwF1L8fjwC5+kOlNXD7o7umZBDmE9NwYHMlH6mp9mIYI87Zo1Wny9iIHl8CoYFDrtrFrRcKUH9drU0kJUjRV7YgbokpHlAxJfQ6BWoikE4xawBhJI/A4zvVkmTyGBKey6DACrk6BmYW/Mt+tvz9aOjp8qDFMjOOAZzm26eXaA/Bafwrm5pta5KQDioRW71atyhUwnPzaT5CT7d9rnIuBOZ5akLXwaIJDcro3JzFOYU8UaDqGPTRyYY6JEvcafDvb+ZzijuMhHFdOfoLkT4J6LiedBQU9+fyKwjhUXnF0uPdldw6iM1BJUda2ReseTRfw5RZ1TdOIzzzzap+Lsn8FYBOPEtlFXEoUWh17WD1EJDvA6qyyKI7CxApdqJATuTGrMOMg5wdELMo0kT8Fs/hewS27eVYoVr1+Tj2dOJlnE8XNRr2VMhROKPshFTPGMGmjKrD1GFuUv2oXCkOUHsUTbqzwx/Ism4WfysJz8NjSi0zbcIuVEcepxXMqsLaJCxRDmI4z3FA+VMzBzlHhbc7lxp50WvBsmVleI142gRNki3wxSvUlcF8alwow7OH8IWy9HzPdcjjdNULGI0zqtgOBlgf1ylEmtm96ZcNHaV6luNfcSvR4rnKDhXniAhYmhZUfvO3LEZjAc9PFpZSLCtfElZ5n+yEYYoHPvKj5BQPUeD6Di8vmaxHpE6iG6392z3bH8f5ur2E5oEWpCY4NQfBBPDLA8OD/BZgFwakwgx/qTBHUykG0Chc3TV4Hpy9CZcAuExXYPmi2t8sgovNm9B4GzATz2yUs5GDhVQyiqvagpdsrtP1e/meQQbvo3GFJA+ehbB7lM0Q+wkburquoHDb3LHWYQaUXqy14zYFemqubNlWxw+SDRG2sihwnCEMNKy4EV3Ht+TiWEZkpdbU4rgbCXbyrkqoAhNgUtbvsy7PSTIfG/P+bA23/X6oWAFzWg9ZKOt3stNYjPlAxkDyvkkrcetMZUOrkw7LcHHdhMX3cT6gKBKxtLqH4QGcOD1je2amNf53IzTZaaxhUyeQBFjPDmXpXLhwdLXurzg8IdG3W3BJROLC0eP+2X6CyfYFGYVHhRAUft+oVp+q2gtN+twoydSvuCUILe+dvf5MLuserP4V/+n1LB42LMUP7ga3ypcg4+PJTsHGN5GSbMpSJA/1XO1BpP9u+xyZEvi/wDgNoX9dmt6Xi4amJqpsOA9LfbGsv8VUwDP6FTfZWbj2WFnHl2rPHJOfeXPR+uCqOHycXKXNDRI+Jv1B2ck= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87cf417a-8310-4d53-1c96-08d9b0f325fe X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2021 15:41:01.4351 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Yofpo0voj595fe0991/FtxfdZaOUtCDjvJAxvvdT9iA8QO6XlFr9fPmudAwvpbeqh/1hfAzysZo33oiM0Hi+pw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_074102_875538_6D0B975B X-CRM114-Status: GOOD ( 11.61 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We add EXTRA_CFLAGS to the common CFLAGS of top-level Makefile which will allow users to pass additional compile-time flags such as "-static". Signed-off-by: Anup Patel --- tools/testing/selftests/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index c4e34717826a..ee6740e9ecdb 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -131,7 +131,7 @@ endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ - -I$( X-Patchwork-Id: 12641015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D734DC433EF for ; Fri, 26 Nov 2021 15:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B4IWxHLFcZa0SlMoaaKC8ADHQRujR+XCXjwfwFgwlpQ=; b=1UZ5J0avqx11Wp SrPLu2nQekqM155odh1G7xd7M578+5CDFO3XCS46PcnfA+0FlbiGGx5fWXaJpXj2cL3lA/V4xaR0Y rkBHiDWROMNJeS5mBO8sSpgsoAe1IAczPD7Qhy1OZag5ByclCz0S4HN9gJMOhQYHYKB1wWLpJR5mg QK6omsQp5QqSi3AhEcQVOF97GMHneBTpGfwRpmg/cKuTNtXboHRZgM+HnYNnRlRtjLz1nQGu9Lh4v Gt/95e7wIniwN1xhb2zLYWU2ux4mhHzfRo+EM+HCh5aRERPKvCm3iuvPc7smrwLd9Jk9IBHYkjgsM Bkw5R00bE+HiiM8O3Ytw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLd-00Ay1L-1L; Fri, 26 Nov 2021 15:41:13 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqdLY-00Axyl-ST; Fri, 26 Nov 2021 15:41:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637941266; x=1669477266; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Dux3wo0FAozbYqJip+sXv5CE0sOpu9PGfSBNcXtaU2c=; b=F1qkJ9LhChS/A5IGP8/ousaPhPfwTFv+TJ/TV/uOhmDNN7qTpYoewkQ1 PonQjPOZy39HrJcAi1xhtw0mzBXbrJM8Q65OXVAu8DfWdMJdT72j6ZKiY VTr/Kqnf3N48uyKMvnEVWda65gzmEyb4W0b65uY46enXn8j1262FlP1cV XTPEVjzAoufm7ms939WNWkS+PowKqhziH7s7wIMRH4J5/PBXIQowbF2QK fHe88zvnGuC+b61Vep0/BpqrBXEo5ahPXyY2TXC0SY/dC0SoXKd39uRJJ aC1Kneyei/7haBi+LNIQRU4WgteKxZ4m6mY+IaDxmlvaR5J4UI1Q2jZoX A==; X-IronPort-AV: E=Sophos;i="5.87,266,1631548800"; d="scan'208";a="186749396" Received: from mail-mw2nam10lp2100.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.100]) by ob1.hgst.iphmx.com with ESMTP; 26 Nov 2021 23:41:06 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a4M4I2MLNX0ZlrnV7mouyFFvRaTdR8TSc+QIlBnOvqGeTAOGFL7++RLLS6BSkW25M3WHSrLkapaOdZDAxXn61GeIBHctgMyGJM8yNlxJpCcZnmgAGZYjcP34m30JhdeK2h0fr1Ab8ehYq0fy51068GMVmZla4kogyI6jrOw1TD+S7rOeQLFnGjMIGyFtwFbvUaO7OnTaru2T4YRDdGizOqgYJaD/bjrcHDTqicxDThFAeBvsWUFZhZXHkJeAlks60qLLer/MOBkEXKrRrwsdSMtb45Aktuqt0Doc4HXywhL5T7qOIY01LpMi6Et6YVMIt+RsTcjeRdZ6FywIuZKChw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Gr7eizanvc1LDHz+mWq1ok6UH6cJxQIacC3czFLZ2j0=; b=JoeMqWijNu9dNQQccDKj9VIBuSpI/YsbVeqAC1Imi6SaEyS/ZX+GG96a0hz4t6sBr8z0OGS1TFqNrf7oaQewk+tco5y2H88Y+JBB2nc9vLuFr6FjzWKE0nFfnGT/qji8eAt1V/AGmm9lEb/G/jSu7QOByZCKZz0VQfmpEq+EE1prPjW/4t6psMZy7/iUS0T5yNUVYupZz/W/4hRuZ+tS8ju2A4Xmjau5jhGb5FoHEwiifHImMtOc7u13+Af3I+xVghDBnTdG2q4Z8sotw8eCSWCD9OwbYWRUMxP4OpTdz7527chUKfqVHRU4Cg8aqTELhX8RO3jlpYoqMtrWPmZ06A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gr7eizanvc1LDHz+mWq1ok6UH6cJxQIacC3czFLZ2j0=; b=CjePavTnC0BMry/RTnjRvGXO6V1/3nbSl4Lqcn6bWNwrB8WdB800P3T1R/OkysvJuMTz7oCTO+K88oRvqKq9cpJvI1nIegYAZwHphG3qVAg4uMjN2Ey7s70pSle0mAGsEHrQ+zW3cl2HogRFSB4gNs7s12akfh3K07SCa8U+S1A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8330.namprd04.prod.outlook.com (2603:10b6:303:135::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19; Fri, 26 Nov 2021 15:41:05 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4734.023; Fri, 26 Nov 2021 15:41:05 +0000 From: Anup Patel To: Paolo Bonzini , Shuah Khan , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel Subject: [PATCH 4/4] KVM: selftests: Add initial support for RISC-V 64-bit Date: Fri, 26 Nov 2021 21:10:20 +0530 Message-Id: <20211126154020.342924-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126154020.342924-1-anup.patel@wdc.com> References: <20211126154020.342924-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.118.153) by MAXPR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.20 via Frontend Transport; Fri, 26 Nov 2021 15:41:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e068b0aa-0dc1-40cd-30ab-08d9b0f3288d X-MS-TrafficTypeDiagnostic: CO6PR04MB8330: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QwsQa+AtyODjeG9QueWI8M/H7nNGngpfW4cw3Duvwq9egy4cwu5npCw3CBCa/lRVe0hDS7B1u9AvwD/ql5MoAnHaj18CpbHrH4jp5CaeUJbySRTGePs0qKhOGXJoS4KpxU6sekGj3j3iUGFW9dqEgrd50htOuAAjB9H+SSwoXP7MRAJJOQqFrNzZSlQDmbAktWv9QN0KMCe/edz38wr8Nte+e7ZIVoInEMvLIiURE+VXTcBcpzqKmGZf6pR/WptvCD2JW0XuetsUKKFoNJKdZVmaUk2wtuy/n9QvfRkQIEiWVtw+jxCa9jg0h/RNv6qVDsYVNAWK+vLupjKfYdmoPFrISWLLXwhZO9b8HkJBqzGrq2+OAxj7/b0G9em9EG1GbCHA1sH8MvTsUBrzxyyBtY5ODnT+FEzogUd+wQUpusR5dm/fdmY8Pgqjh9fxrIYXK/Fj8Y8enU9F0Nx6Xo3C0VdBgKc2FxRM5q4ls5uapG522468FVYQE1Se8n+UA4KvO5He8idwcxUdv+EM2v7asrWFSc7q582Ek/BjNpBVjSJRybRY9t9Rq5tzdvAb73O4AldTPklDus9pxT18yrFwEgv79iCrzsGg5RtpSuNxtSup59h6NqX2NUF9gsJrI62ZlBzth9zH4r+D6vH7h5jrBStGfbUEjn0d/9qzeIXfCf0PuIZ1QN16GViXKrPCK894wTcuQgEoPtM0xlwiOdzeUA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(1076003)(54906003)(66946007)(110136005)(38350700002)(82960400001)(26005)(66556008)(186003)(30864003)(44832011)(83380400001)(316002)(6666004)(86362001)(7696005)(956004)(2616005)(7416002)(52116002)(508600001)(2906002)(5660300002)(36756003)(55016003)(8886007)(38100700002)(66476007)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +qQGtwSVsmVPDgrX/imt3oGjcajchWjSJMLgQFFfAo3HANX6dwY6IzrdEvRl1nB48yzzJHeiU0tmiQSKxOKA9zk/hYoENKR5Jd2FTvKsbVaTC3E2taIObc1YZW/b1yswy2ed/vRXIZ3b2LWUfqh+v5GpNPYYoTpgSDe2dw9GNQCfiDPf0JD97WOeDmtckIbWp3Dj1XsWGUwGhhI6S89hJJv5M0sdVjuKu9Zb4HgXKuOzdxpMKCahjc6JoKVCibqSOWycy8u9dV+5NTBwU4HFALjCh0djqkKuxoeYD7us5ahHCVWfTzyjMMfSvb3iP5+NDQAz9ZHMEtTtCeuwXSJGmigGWhpTtL3EZphTi7Zrz98J5Oys6B+Z4a9FQoFRDhpq1agwDKuUeGmntQocMWqoJt60KjGPBkIfZM48fD72uLptTsF3jt+RKKUGiWiCyGxEu9xYD1dNzBdVvHfitPelrGet6whRCwFK28B5I+36jhSIR0YUHZ4itW1o8hEXAaoLQLEASSgQapc9FR1dmcvW8qKn15dW3zMwISruunqD5hBiZvpfSVA6hmDvQmGxe3uUr4E1XWby2Bw02eFaYRife//mMTXCpMlw0iQCCVgbSy/kKx7P7rgXQSA1clTL/WXrn+fMTXh2tZ8170/ja6/QnUVOHwWQMej3rkv6s6+GvFAnVmsCNLn0kLZV8DvtHVmPf652uiKEMFdoFm/b2lD6TZEQAKd7pXK4SLcCbkiGKFw41fsyl24ER+bRdWWHrPmE3lsMq2zBmSqcjAokHstSIF6986AIwh/DTDvO93hCdhqzzQxLzPReJDOYUbZyMe0rmftXOwNpo9TkTjMy1bmAHEwnZomMZF/19tpzzmJFR7sAhdUfaswMOZ20i9euiLs+gOObImIUNg5LWMRBXYm/6rMUYSFm0Yq63ME0gZbEZomWxcpO1rSM4mPgUYeqEk4ZZrFj5rQh3JMhrQqlXVEztFmXwzhTQqmn1LB7hRUhtzr7Lwitb3UuGzLqsQ6B+j4gbPBnBAKNffrxQWJXeLwAO70ezs312UHdpl84TMd8RIg5uMqpY4JH9zOHLQK/wbCCJMgabghNZ71kcKwtFW2nVzdWTdkfijP9gXuzqZW2MFbx7eMIK6APRTqUHH9XCkle0MJ/Nagq0tASHx97u668yWBxkkWOmYJz44/lghrkkB1pjCOdvgqGcrAVzBR2FhxF90Wq0IXoUkiptQyLoLg3SgBnZk8JwEpyp8rPlOPBX7ZVhXAPbJ5fv8/KsevTKhYoYBwMar/w5PUvV/yQ+XgM15yaZix7uqcaBB8XS6ssK5y0bzrgau/8UtR0I7kAM6dhr8PCya9be7YREBmUNIdNxg6Ln5fqyrSpgvhL/544eNzB3nSUJT6paQSgBK5mewm+9NLcp34blq/sGqFcmiXW8hYfwQw8C3D7eCJEuny+DhHHLEkZiICrKEl7ymiSFka3i+bfDLa72pU6f5h2yDiDk4lokFWDOGjE4+VSsLd5aJ1XvBTtQX31ArD/oe+XuY2nqkw9UtnMNBnAiXNtc1YX/oWW+ctIbG+D7rNGbGD5ggfKKSdudPwEXjmXR9u+7YM2xUNSQZLul5I423GdWw9+IgdzUAfqknWgJH2uusk9rVo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: e068b0aa-0dc1-40cd-30ab-08d9b0f3288d X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2021 15:41:05.6615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Sm+5+/sSyJJH8XiruoZE0OSrINJBrRHAgeOohaAFtlae5IU77LLxoD77x1/fQV7CUpxA4u8gbwp2/5yRIJCKtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_074108_980382_AA406B07 X-CRM114-Status: GOOD ( 17.47 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We add initial support for RISC-V 64-bit in KVM selftests using which we can cross-compile and run arch independent tests such as: demand_paging_test dirty_log_test kvm_create_max_vcpus, kvm_page_table_test set_memory_region_test kvm_binary_stats_test All VM guest modes defined in kvm_util.h require at least 48-bit guest virtual address so to use KVM RISC-V selftests hardware need to support at least Sv48 MMU for guest (i.e. VS-mode). Signed-off-by: Anup Patel --- tools/testing/selftests/kvm/Makefile | 12 + .../testing/selftests/kvm/include/kvm_util.h | 10 + .../selftests/kvm/include/riscv/processor.h | 135 +++++++ tools/testing/selftests/kvm/lib/guest_modes.c | 10 + .../selftests/kvm/lib/riscv/processor.c | 362 ++++++++++++++++++ tools/testing/selftests/kvm/lib/riscv/ucall.c | 87 +++++ 6 files changed, 616 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/riscv/processor.h create mode 100644 tools/testing/selftests/kvm/lib/riscv/processor.c create mode 100644 tools/testing/selftests/kvm/lib/riscv/ucall.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index ee6740e9ecdb..2d825d1e7ff2 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -32,11 +32,16 @@ endif ifeq ($(ARCH),s390) UNAME_M := s390x endif +# Set UNAME_M riscv compile/install to work +ifeq ($(ARCH),riscv) + UNAME_M := riscv +endif LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/rbtree.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c LIBKVM_x86_64 = lib/x86_64/apic.c lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c lib/aarch64/gic.c lib/aarch64/gic_v3.c lib/aarch64/vgic.c LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c +LIBKVM_riscv = lib/riscv/processor.c lib/riscv/ucall.c TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features @@ -117,6 +122,13 @@ TEST_GEN_PROGS_s390x += rseq_test TEST_GEN_PROGS_s390x += set_memory_region_test TEST_GEN_PROGS_s390x += kvm_binary_stats_test +TEST_GEN_PROGS_riscv += demand_paging_test +TEST_GEN_PROGS_riscv += dirty_log_test +TEST_GEN_PROGS_riscv += kvm_create_max_vcpus +TEST_GEN_PROGS_riscv += kvm_page_table_test +TEST_GEN_PROGS_riscv += set_memory_region_test +TEST_GEN_PROGS_riscv += kvm_binary_stats_test + TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) LIBKVM += $(LIBKVM_$(UNAME_M)) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 6a1a37f30494..c23e5be14862 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -69,6 +69,16 @@ enum vm_guest_mode { #define MIN_PAGE_SHIFT 12U #define ptes_per_page(page_size) ((page_size) / 16) +#elif defined(__riscv) + +#if __riscv_xlen == 32 +#error "RISC-V 32-bit kvm selftests not supported" +#endif + +#define VM_MODE_DEFAULT VM_MODE_P40V48_4K +#define MIN_PAGE_SHIFT 12U +#define ptes_per_page(page_size) ((page_size) / 8) + #endif #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h new file mode 100644 index 000000000000..dc284c6bdbc3 --- /dev/null +++ b/tools/testing/selftests/kvm/include/riscv/processor.h @@ -0,0 +1,135 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * RISC-V processor specific defines + * + * Copyright (C) 2021 Western Digital Corporation or its affiliates. + */ +#ifndef SELFTEST_KVM_PROCESSOR_H +#define SELFTEST_KVM_PROCESSOR_H + +#include "kvm_util.h" +#include + +static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t idx, + uint64_t size) +{ + return KVM_REG_RISCV | type | idx | size; +} + +#if __riscv_xlen == 64 +#define KVM_REG_SIZE_ULONG KVM_REG_SIZE_U64 +#else +#define KVM_REG_SIZE_ULONG KVM_REG_SIZE_U32 +#endif + +#define RISCV_CONFIG_REG(name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, \ + KVM_REG_RISCV_CONFIG_REG(name), \ + KVM_REG_SIZE_ULONG) + +#define RISCV_CORE_REG(name) __kvm_reg_id(KVM_REG_RISCV_CORE, \ + KVM_REG_RISCV_CORE_REG(name), \ + KVM_REG_SIZE_ULONG) + +#define RISCV_CSR_REG(name) __kvm_reg_id(KVM_REG_RISCV_CSR, \ + KVM_REG_RISCV_CSR_REG(name), \ + KVM_REG_SIZE_ULONG) + +#define RISCV_TIMER_REG(name) __kvm_reg_id(KVM_REG_RISCV_TIMER, \ + KVM_REG_RISCV_TIMER_REG(name), \ + KVM_REG_SIZE_U64) + +static inline void get_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, + unsigned long *addr) +{ + struct kvm_one_reg reg; + + reg.id = id; + reg.addr = (unsigned long)addr; + vcpu_get_reg(vm, vcpuid, ®); +} + +static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, + unsigned long val) +{ + struct kvm_one_reg reg; + + reg.id = id; + reg.addr = (unsigned long)&val; + vcpu_set_reg(vm, vcpuid, ®); +} + +/* L3 index Bit[47:39] */ +#define PGTBL_L3_INDEX_MASK 0x0000FF8000000000ULL +#define PGTBL_L3_INDEX_SHIFT 39 +#define PGTBL_L3_BLOCK_SHIFT 39 +#define PGTBL_L3_BLOCK_SIZE 0x0000008000000000ULL +#define PGTBL_L3_MAP_MASK (~(PGTBL_L3_BLOCK_SIZE - 1)) +/* L2 index Bit[38:30] */ +#define PGTBL_L2_INDEX_MASK 0x0000007FC0000000ULL +#define PGTBL_L2_INDEX_SHIFT 30 +#define PGTBL_L2_BLOCK_SHIFT 30 +#define PGTBL_L2_BLOCK_SIZE 0x0000000040000000ULL +#define PGTBL_L2_MAP_MASK (~(PGTBL_L2_BLOCK_SIZE - 1)) +/* L1 index Bit[29:21] */ +#define PGTBL_L1_INDEX_MASK 0x000000003FE00000ULL +#define PGTBL_L1_INDEX_SHIFT 21 +#define PGTBL_L1_BLOCK_SHIFT 21 +#define PGTBL_L1_BLOCK_SIZE 0x0000000000200000ULL +#define PGTBL_L1_MAP_MASK (~(PGTBL_L1_BLOCK_SIZE - 1)) +/* L0 index Bit[20:12] */ +#define PGTBL_L0_INDEX_MASK 0x00000000001FF000ULL +#define PGTBL_L0_INDEX_SHIFT 12 +#define PGTBL_L0_BLOCK_SHIFT 12 +#define PGTBL_L0_BLOCK_SIZE 0x0000000000001000ULL +#define PGTBL_L0_MAP_MASK (~(PGTBL_L0_BLOCK_SIZE - 1)) + +#define PGTBL_PTE_ADDR_MASK 0x003FFFFFFFFFFC00ULL +#define PGTBL_PTE_ADDR_SHIFT 10 +#define PGTBL_PTE_RSW_MASK 0x0000000000000300ULL +#define PGTBL_PTE_RSW_SHIFT 8 +#define PGTBL_PTE_DIRTY_MASK 0x0000000000000080ULL +#define PGTBL_PTE_DIRTY_SHIFT 7 +#define PGTBL_PTE_ACCESSED_MASK 0x0000000000000040ULL +#define PGTBL_PTE_ACCESSED_SHIFT 6 +#define PGTBL_PTE_GLOBAL_MASK 0x0000000000000020ULL +#define PGTBL_PTE_GLOBAL_SHIFT 5 +#define PGTBL_PTE_USER_MASK 0x0000000000000010ULL +#define PGTBL_PTE_USER_SHIFT 4 +#define PGTBL_PTE_EXECUTE_MASK 0x0000000000000008ULL +#define PGTBL_PTE_EXECUTE_SHIFT 3 +#define PGTBL_PTE_WRITE_MASK 0x0000000000000004ULL +#define PGTBL_PTE_WRITE_SHIFT 2 +#define PGTBL_PTE_READ_MASK 0x0000000000000002ULL +#define PGTBL_PTE_READ_SHIFT 1 +#define PGTBL_PTE_PERM_MASK (PGTBL_PTE_EXECUTE_MASK | \ + PGTBL_PTE_WRITE_MASK | \ + PGTBL_PTE_READ_MASK) +#define PGTBL_PTE_VALID_MASK 0x0000000000000001ULL +#define PGTBL_PTE_VALID_SHIFT 0 + +#define PGTBL_PAGE_SIZE PGTBL_L0_BLOCK_SIZE +#define PGTBL_PAGE_SIZE_SHIFT PGTBL_L0_BLOCK_SHIFT + +#define SATP_PPN _AC(0x00000FFFFFFFFFFF, UL) +#define SATP_MODE_39 _AC(0x8000000000000000, UL) +#define SATP_MODE_48 _AC(0x9000000000000000, UL) +#define SATP_ASID_BITS 16 +#define SATP_ASID_SHIFT 44 +#define SATP_ASID_MASK _AC(0xFFFF, UL) + +#define SBI_EXT_EXPERIMENTAL_START 0x08000000 +#define SBI_EXT_EXPERIMENTAL_END 0x08FFFFFF + +#define KVM_RISCV_SELFTESTS_SBI_EXT SBI_EXT_EXPERIMENTAL_END + +struct sbiret { + long error; + long value; +}; + +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5); + +#endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c index c330f414ef96..6847f9905ddb 100644 --- a/tools/testing/selftests/kvm/lib/guest_modes.c +++ b/tools/testing/selftests/kvm/lib/guest_modes.c @@ -38,6 +38,16 @@ void guest_modes_append_default(void) guest_mode_append(VM_MODE_P47V64_4K, true, true); } #endif +#ifdef __riscv + { + unsigned int sz = kvm_check_cap(KVM_CAP_RISCV_VM_GPA_SIZE); + + if (sz >= 52) + guest_mode_append(VM_MODE_P52V48_4K, true, true); + if (sz >= 48) + guest_mode_append(VM_MODE_P48V48_4K, true, true); + } +#endif } void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg) diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c new file mode 100644 index 000000000000..d377f2603d98 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -0,0 +1,362 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * RISC-V code + * + * Copyright (C) 2021 Western Digital Corporation or its affiliates. + */ + +#include +#include + +#include "kvm_util.h" +#include "../kvm_util_internal.h" +#include "processor.h" + +#define DEFAULT_RISCV_GUEST_STACK_VADDR_MIN 0xac0000 + +static uint64_t page_align(struct kvm_vm *vm, uint64_t v) +{ + return (v + vm->page_size) & ~(vm->page_size - 1); +} + +static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry) +{ + return ((entry & PGTBL_PTE_ADDR_MASK) >> PGTBL_PTE_ADDR_SHIFT) << + PGTBL_PAGE_SIZE_SHIFT; +} + +static uint64_t ptrs_per_pte(struct kvm_vm *vm) +{ + return PGTBL_PAGE_SIZE / sizeof(uint64_t); +} + +static uint64_t pte_index_mask[] = { + PGTBL_L0_INDEX_MASK, + PGTBL_L1_INDEX_MASK, + PGTBL_L2_INDEX_MASK, + PGTBL_L3_INDEX_MASK, +}; + +static uint32_t pte_index_shift[] = { + PGTBL_L0_INDEX_SHIFT, + PGTBL_L1_INDEX_SHIFT, + PGTBL_L2_INDEX_SHIFT, + PGTBL_L3_INDEX_SHIFT, +}; + +static uint64_t pte_index(struct kvm_vm *vm, vm_vaddr_t gva, int level) +{ + TEST_ASSERT(level > -1, + "Negative page table level (%d) not possible", level); + TEST_ASSERT(level < vm->pgtable_levels, + "Invalid page table level (%d)", level); + + return (gva & pte_index_mask[level]) >> pte_index_shift[level]; +} + +void virt_pgd_alloc(struct kvm_vm *vm) +{ + if (!vm->pgd_created) { + vm_paddr_t paddr = vm_phy_pages_alloc(vm, + page_align(vm, ptrs_per_pte(vm) * 8) / vm->page_size, + KVM_GUEST_PAGE_TABLE_MIN_PADDR, 0); + vm->pgd = paddr; + vm->pgd_created = true; + } +} + +void virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr) +{ + uint64_t *ptep, next_ppn; + int level = vm->pgtable_levels - 1; + + TEST_ASSERT((vaddr % vm->page_size) == 0, + "Virtual address not on page boundary,\n" + " vaddr: 0x%lx vm->page_size: 0x%x", vaddr, vm->page_size); + TEST_ASSERT(sparsebit_is_set(vm->vpages_valid, + (vaddr >> vm->page_shift)), + "Invalid virtual address, vaddr: 0x%lx", vaddr); + TEST_ASSERT((paddr % vm->page_size) == 0, + "Physical address not on page boundary,\n" + " paddr: 0x%lx vm->page_size: 0x%x", paddr, vm->page_size); + TEST_ASSERT((paddr >> vm->page_shift) <= vm->max_gfn, + "Physical address beyond maximum supported,\n" + " paddr: 0x%lx vm->max_gfn: 0x%lx vm->page_size: 0x%x", + paddr, vm->max_gfn, vm->page_size); + + ptep = addr_gpa2hva(vm, vm->pgd) + pte_index(vm, vaddr, level) * 8; + if (!*ptep) { + next_ppn = vm_alloc_page_table(vm) >> PGTBL_PAGE_SIZE_SHIFT; + *ptep = (next_ppn << PGTBL_PTE_ADDR_SHIFT) | + PGTBL_PTE_VALID_MASK; + } + level--; + + while (level > -1) { + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + + pte_index(vm, vaddr, level) * 8; + if (!*ptep && level > 0) { + next_ppn = vm_alloc_page_table(vm) >> + PGTBL_PAGE_SIZE_SHIFT; + *ptep = (next_ppn << PGTBL_PTE_ADDR_SHIFT) | + PGTBL_PTE_VALID_MASK; + } + level--; + } + + paddr = paddr >> PGTBL_PAGE_SIZE_SHIFT; + *ptep = (paddr << PGTBL_PTE_ADDR_SHIFT) | + PGTBL_PTE_PERM_MASK | PGTBL_PTE_VALID_MASK; +} + +vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) +{ + uint64_t *ptep; + int level = vm->pgtable_levels - 1; + + if (!vm->pgd_created) + goto unmapped_gva; + + ptep = addr_gpa2hva(vm, vm->pgd) + pte_index(vm, gva, level) * 8; + if (!ptep) + goto unmapped_gva; + level--; + + while (level > -1) { + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + + pte_index(vm, gva, level) * 8; + if (!ptep) + goto unmapped_gva; + level--; + } + + return pte_addr(vm, *ptep) + (gva & (vm->page_size - 1)); + +unmapped_gva: + TEST_FAIL("No mapping for vm virtual address gva: 0x%lx level: %d", + gva, level); + exit(1); +} + +static void pte_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent, + uint64_t page, int level) +{ +#ifdef DEBUG + static const char *const type[] = { "pte", "pmd", "pud", "p4d"}; + uint64_t pte, *ptep; + + if (level < 0) + return; + + for (pte = page; pte < page + ptrs_per_pte(vm) * 8; pte += 8) { + ptep = addr_gpa2hva(vm, pte); + if (!*ptep) + continue; + fprintf(stream, "%*s%s: %lx: %lx at %p\n", indent, "", + type[level], pte, *ptep, ptep); + pte_dump(stream, vm, indent + 1, + pte_addr(vm, *ptep), level - 1); + } +#endif +} + +void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent) +{ + int level = vm->pgtable_levels - 1; + uint64_t pgd, *ptep; + + if (!vm->pgd_created) + return; + + for (pgd = vm->pgd; pgd < vm->pgd + ptrs_per_pte(vm) * 8; pgd += 8) { + ptep = addr_gpa2hva(vm, pgd); + if (!*ptep) + continue; + fprintf(stream, "%*spgd: %lx: %lx at %p\n", indent, "", + pgd, *ptep, ptep); + pte_dump(stream, vm, indent + 1, + pte_addr(vm, *ptep), level - 1); + } +} + +void riscv_vcpu_mmu_setup(struct kvm_vm *vm, int vcpuid) +{ + unsigned long satp; + + /* + * The RISC-V Sv48 MMU mode supports 56-bit physical address + * for 48-bit virtual address with 4KB last level page size. + */ + switch (vm->mode) { + case VM_MODE_P52V48_4K: + case VM_MODE_P48V48_4K: + case VM_MODE_P40V48_4K: + break; + default: + TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode); + } + + satp = (vm->pgd >> PGTBL_PAGE_SIZE_SHIFT) & SATP_PPN; + satp |= SATP_MODE_48; + + set_reg(vm, vcpuid, RISCV_CSR_REG(satp), satp); +} + +void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) +{ + struct kvm_riscv_core core; + + get_reg(vm, vcpuid, RISCV_CORE_REG(mode), &core.mode); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.pc), &core.regs.pc); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.ra), &core.regs.ra); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.sp), &core.regs.sp); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.gp), &core.regs.gp); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.tp), &core.regs.tp); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t0), &core.regs.t0); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t1), &core.regs.t1); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t2), &core.regs.t2); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s0), &core.regs.s0); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s1), &core.regs.s1); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a0), &core.regs.a0); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a1), &core.regs.a1); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a2), &core.regs.a2); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a3), &core.regs.a3); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a4), &core.regs.a4); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a5), &core.regs.a5); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a6), &core.regs.a6); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.a7), &core.regs.a7); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s2), &core.regs.s2); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s3), &core.regs.s3); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s4), &core.regs.s4); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s5), &core.regs.s5); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s6), &core.regs.s6); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s7), &core.regs.s7); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s8), &core.regs.s8); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s9), &core.regs.s9); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s10), &core.regs.s10); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.s11), &core.regs.s11); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t3), &core.regs.t3); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t4), &core.regs.t4); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t5), &core.regs.t5); + get_reg(vm, vcpuid, RISCV_CORE_REG(regs.t6), &core.regs.t6); + + fprintf(stream, + " MODE: 0x%lx\n", core.mode); + fprintf(stream, + " PC: 0x%016lx RA: 0x%016lx SP: 0x%016lx GP: 0x%016lx\n", + core.regs.pc, core.regs.ra, core.regs.sp, core.regs.gp); + fprintf(stream, + " TP: 0x%016lx T0: 0x%016lx T1: 0x%016lx T2: 0x%016lx\n", + core.regs.tp, core.regs.t0, core.regs.t1, core.regs.t2); + fprintf(stream, + " S0: 0x%016lx S1: 0x%016lx A0: 0x%016lx A1: 0x%016lx\n", + core.regs.s0, core.regs.s1, core.regs.a0, core.regs.a1); + fprintf(stream, + " A2: 0x%016lx A3: 0x%016lx A4: 0x%016lx A5: 0x%016lx\n", + core.regs.a2, core.regs.a3, core.regs.a4, core.regs.a5); + fprintf(stream, + " A6: 0x%016lx A7: 0x%016lx S2: 0x%016lx S3: 0x%016lx\n", + core.regs.a6, core.regs.a7, core.regs.s2, core.regs.s3); + fprintf(stream, + " S4: 0x%016lx S5: 0x%016lx S6: 0x%016lx S7: 0x%016lx\n", + core.regs.s4, core.regs.s5, core.regs.s6, core.regs.s7); + fprintf(stream, + " S8: 0x%016lx S9: 0x%016lx S10: 0x%016lx S11: 0x%016lx\n", + core.regs.s8, core.regs.s9, core.regs.s10, core.regs.s11); + fprintf(stream, + " T3: 0x%016lx T4: 0x%016lx T5: 0x%016lx T6: 0x%016lx\n", + core.regs.t3, core.regs.t4, core.regs.t5, core.regs.t6); +} + +static void guest_hang(void) +{ + while (1) + ; +} + +void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) +{ + int r; + size_t stack_size = vm->page_size == 4096 ? + DEFAULT_STACK_PGS * vm->page_size : + vm->page_size; + unsigned long stack_vaddr = vm_vaddr_alloc(vm, stack_size, + DEFAULT_RISCV_GUEST_STACK_VADDR_MIN); + unsigned long current_gp = 0; + struct kvm_mp_state mps; + + vm_vcpu_add(vm, vcpuid); + riscv_vcpu_mmu_setup(vm, vcpuid); + + /* + * With SBI HSM support in KVM RISC-V, all secondary VCPUs are + * powered-off by default so we ensure that all secondary VCPUs + * are powered-on using KVM_SET_MP_STATE ioctl(). + */ + mps.mp_state = KVM_MP_STATE_RUNNABLE; + r = _vcpu_ioctl(vm, vcpuid, KVM_SET_MP_STATE, &mps); + TEST_ASSERT(!r, "IOCTL KVM_SET_MP_STATE failed (error %d)", r); + + /* Setup global pointer of guest to be same as the host */ + asm volatile ( + "add %0, gp, zero" : "=r" (current_gp) : : "memory"); + set_reg(vm, vcpuid, RISCV_CORE_REG(regs.gp), current_gp); + + /* Setup stack pointer and program counter of guest */ + set_reg(vm, vcpuid, RISCV_CORE_REG(regs.sp), + stack_vaddr + stack_size); + set_reg(vm, vcpuid, RISCV_CORE_REG(regs.pc), + (unsigned long)guest_code); + + /* Setup default exception vector of guest */ + set_reg(vm, vcpuid, RISCV_CSR_REG(stvec), + (unsigned long)guest_hang); +} + +void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) +{ + va_list ap; + uint64_t id = RISCV_CORE_REG(regs.a0); + int i; + + TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n" + " num: %u\n", num); + + va_start(ap, num); + + for (i = 0; i < num; i++) { + switch (i) { + case 0: + id = RISCV_CORE_REG(regs.a0); + break; + case 1: + id = RISCV_CORE_REG(regs.a1); + break; + case 2: + id = RISCV_CORE_REG(regs.a2); + break; + case 3: + id = RISCV_CORE_REG(regs.a3); + break; + case 4: + id = RISCV_CORE_REG(regs.a4); + break; + case 5: + id = RISCV_CORE_REG(regs.a5); + break; + case 6: + id = RISCV_CORE_REG(regs.a6); + break; + case 7: + id = RISCV_CORE_REG(regs.a7); + break; + }; + set_reg(vm, vcpuid, id, va_arg(ap, uint64_t)); + } + + va_end(ap); +} + +void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid) +{ +} diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c new file mode 100644 index 000000000000..9e42d8248fa6 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ucall support. A ucall is a "hypercall to userspace". + * + * Copyright (C) 2021 Western Digital Corporation or its affiliates. + */ + +#include + +#include "kvm_util.h" +#include "../kvm_util_internal.h" +#include "processor.h" + +void ucall_init(struct kvm_vm *vm, void *arg) +{ +} + +void ucall_uninit(struct kvm_vm *vm) +{ +} + +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) +{ + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); + register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); + struct sbiret ret; + + asm volatile ( + "ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) + : "memory"); + ret.error = a0; + ret.value = a1; + + return ret; +} + +void ucall(uint64_t cmd, int nargs, ...) +{ + struct ucall uc = { + .cmd = cmd, + }; + va_list va; + int i; + + nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; + + va_start(va, nargs); + for (i = 0; i < nargs; ++i) + uc.args[i] = va_arg(va, uint64_t); + va_end(va); + + sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT, 0, (vm_vaddr_t)&uc, + 0, 0, 0, 0, 0); +} + +uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc) +{ + struct kvm_run *run = vcpu_state(vm, vcpu_id); + struct ucall ucall = {}; + + if (uc) + memset(uc, 0, sizeof(*uc)); + + if (run->exit_reason == KVM_EXIT_RISCV_SBI && + run->riscv_sbi.extension_id == KVM_RISCV_SELFTESTS_SBI_EXT && + run->riscv_sbi.function_id == 0) { + memcpy(&ucall, addr_gva2hva(vm, run->riscv_sbi.args[0]), + sizeof(ucall)); + + vcpu_run_complete_io(vm, vcpu_id); + if (uc) + memcpy(uc, &ucall, sizeof(ucall)); + } + + return ucall.cmd; +}