From patchwork Wed Nov 21 05:28:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 10691983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C06B16B1 for ; Wed, 21 Nov 2018 05:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89EF62AFB4 for ; Wed, 21 Nov 2018 05:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B69D2AF07; Wed, 21 Nov 2018 05:28:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D406B2AF07 for ; Wed, 21 Nov 2018 05:28:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 844096B2443; Wed, 21 Nov 2018 00:28:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7F4136B2445; Wed, 21 Nov 2018 00:28:37 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BC266B2446; Wed, 21 Nov 2018 00:28:37 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 1D5406B2443 for ; Wed, 21 Nov 2018 00:28:37 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id m13so6098471pls.15 for ; Tue, 20 Nov 2018 21:28:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:message-id; bh=ZKOcqD48YXAqj8TMeKnjTpqcutPKeFNxZC/X7bxghsI=; b=F3tfN4ro+qAZ2T0k+wpskLl6ubC3kq4Q3Ma9P8L6E9Pa5kvBXYWCKluvZL1mKzQChn KAVnkFnmf/pYL3vhFR02flaO1j015B+TaxNqf6KZIOb7fakjfQM9NA9b+85aUqV1K+R1 hznLwOjB7nAb6EXSh8uzS+bjZ6qYkI2JzZfYBqe/bf+VIHFZNFTsJOOFqXsRXqmmj8UV ROiYy+pAJoBPmPfaNQl7IJTURdcCuAKPyL9LmSOS3YamdZFrA2BTzHcD0cXOPR8Lnm8n 9iVroOg63kAW2R7j7GinkAPvrf0wQ3ob0fH5kKMfpOzjdXingPFf5PNByVmcST4i7Ra3 rdcg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=bharata@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWafmVQBT9CENr1etyCXg1/nXAJGX0C2LoTdNLrahzFyvSxwdM6x ThwYoi63clB6Sdtkyrx1D79UGX9g16iij3AhQUp4dWm982f186jDIfUVvxzixlUeYwznUEqWCAV oHP2ti2AMYxWYapVlfWtoSQ+aIyCpTcCk+JTTC4ghPQCaZ++7NLKjOPeB/ubpNhWMLA== X-Received: by 2002:a63:396:: with SMTP id 144mr4720730pgd.68.1542778116702; Tue, 20 Nov 2018 21:28:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQBwWDF/Uq2ei3A8kBr3gq9k5phcC+YQ/XNBKOudYwR7W7ToVWb0+XHoNrEbMKPC6wA1hR X-Received: by 2002:a63:396:: with SMTP id 144mr4720685pgd.68.1542778115206; Tue, 20 Nov 2018 21:28:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542778115; cv=none; d=google.com; s=arc-20160816; b=gKYZ78UrG751tqvTSbhSqQTExkAIjD6cMk5oj8pe8CmxE/s59GcnnJwu3+2a4iDEw5 5UcqLF76k9r9a1ibjTXMKvJeskJ8g2qcoL2dwqKyOqpJTxyWkn64CYCkLNzoE/8Mnn7R eVJoHDvJnPD7ZOaeClcCOIIeL05FJt5FTAhWyB2Z1B51O+OBxi+HMEf2xnB8HaVIDGYL APmLbEJ41ft5PSP85d3P9fY5jHxCYRB2CceGaYPW6oVv/5TX7R6TRrnGR05sDklkbBAQ x68BquD/o55X6U8HaKjfosrDrzQkvE+hHsC4X+FPqgWM9EOr4b6/AoUYTqBUZwlW60u1 TJqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from; bh=ZKOcqD48YXAqj8TMeKnjTpqcutPKeFNxZC/X7bxghsI=; b=cGD2QlluEKrcbUeJ6s9VD7hDjwj3DR/R7oDhBzv+CVDXrP5YNE6VlaotTOS5sH5L0g jH7olcTLtZ/hnw2EwbFDC8in67mSfdZ47BBTyCTggbtBVPksDlxPr5sD5YxF9uvmqOJU QJN1YG0P0HAY2NaP/aYG+UC6rNyR6USmgvaKROMMNi14m9E8x0lAOG65zThPo/fUJYtT Tcu+lbUFy4/waNyGYwTDr7IyUJyv5TbQjawzu6R8ogNQRTJMMwLU5NjFWhvcOIvRfJVZ LAMbv/G5EmzF+f7Uypq6loeZdnPoGNUCpsDY2+SOuzZ5KGdwBmcUpp3XwWTA8XDpdS6q nagQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=bharata@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id d23si29647316pll.161.2018.11.20.21.28.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 21:28:35 -0800 (PST) Received-SPF: pass (google.com: domain of bharata@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=bharata@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAL5SLo8144313 for ; Wed, 21 Nov 2018 00:28:34 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nw0fasm95-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 21 Nov 2018 00:28:34 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Nov 2018 05:28:32 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 21 Nov 2018 05:28:28 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAL5SRG65964158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 21 Nov 2018 05:28:27 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA0AE4C04A; Wed, 21 Nov 2018 05:28:26 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 634944C044; Wed, 21 Nov 2018 05:28:25 +0000 (GMT) Received: from bharata.in.ibm.com (unknown [9.124.35.234]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 21 Nov 2018 05:28:25 +0000 (GMT) From: Bharata B Rao To: linuxppc-dev@lists.ozlabs.org Cc: kvm-ppc@vger.kernel.org, linux-mm@kvack.org, paulus@au1.ibm.com, benh@linux.ibm.com, aneesh.kumar@linux.vnet.ibm.com, jglisse@redhat.com, linuxram@us.ibm.com, Bharata B Rao Subject: [RFC PATCH v2 4/4] kvmppc: Handle memory plug/unplug to secure VM Date: Wed, 21 Nov 2018 10:58:11 +0530 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121052811.4819-1-bharata@linux.ibm.com> References: <20181121052811.4819-1-bharata@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18112105-4275-0000-0000-000002E44274 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112105-4276-0000-0000-000037F16C15 Message-Id: <20181121052811.4819-5-bharata@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-21_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=956 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811210050 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Register the new memslot with UV during plug and unregister the memslot during unplug. This needs addition of kvm_mr_change argument to kvm_ops->commit_memory_region() Signed-off-by: Bharata B Rao --- arch/powerpc/include/asm/kvm_ppc.h | 6 ++++-- arch/powerpc/include/asm/ucall-api.h | 5 +++++ arch/powerpc/kvm/book3s.c | 5 +++-- arch/powerpc/kvm/book3s_hv.c | 22 +++++++++++++++++++++- arch/powerpc/kvm/book3s_pr.c | 3 ++- arch/powerpc/kvm/powerpc.c | 2 +- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 5f4b6a73789f..1ac920f2e18b 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -224,7 +224,8 @@ extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, extern void kvmppc_core_commit_memory_region(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, const struct kvm_memory_slot *old, - const struct kvm_memory_slot *new); + const struct kvm_memory_slot *new, + enum kvm_mr_change change); extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info); extern void kvmppc_core_flush_memslot(struct kvm *kvm, @@ -294,7 +295,8 @@ struct kvmppc_ops { void (*commit_memory_region)(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, const struct kvm_memory_slot *old, - const struct kvm_memory_slot *new); + const struct kvm_memory_slot *new, + enum kvm_mr_change change); int (*unmap_hva_range)(struct kvm *kvm, unsigned long start, unsigned long end); int (*age_hva)(struct kvm *kvm, unsigned long start, unsigned long end); diff --git a/arch/powerpc/include/asm/ucall-api.h b/arch/powerpc/include/asm/ucall-api.h index 347637995b1b..02c9be311a4f 100644 --- a/arch/powerpc/include/asm/ucall-api.h +++ b/arch/powerpc/include/asm/ucall-api.h @@ -25,4 +25,9 @@ static inline int uv_register_mem_slot(u64 lpid, u64 start_gpa, u64 size, return 0; } +static inline int uv_unregister_mem_slot(u64 lpid, u64 dw0) +{ + return 0; +} + #endif /* _ASM_POWERPC_UCALL_API_H */ diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index fd9893bc7aa1..a35fb4099094 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -830,9 +830,10 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, const struct kvm_memory_slot *old, - const struct kvm_memory_slot *new) + const struct kvm_memory_slot *new, + enum kvm_mr_change change) { - kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new); + kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change); } int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index d7aa85330016..351ce259d8bb 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -75,6 +75,7 @@ #include #include #include +#include #include "book3s.h" @@ -4392,7 +4393,8 @@ static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, const struct kvm_memory_slot *old, - const struct kvm_memory_slot *new) + const struct kvm_memory_slot *new, + enum kvm_mr_change change) { unsigned long npages = mem->memory_size >> PAGE_SHIFT; @@ -4404,6 +4406,24 @@ static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm, */ if (npages) atomic64_inc(&kvm->arch.mmio_update); + /* + * If UV hasn't yet called H_SVM_INIT_START, don't register memslots. + */ + if (!kvm->arch.secure) + return; + + /* + * TODO: Handle KVM_MR_MOVE + */ + if (change == KVM_MR_CREATE) { + uv_register_mem_slot(kvm->arch.lpid, + new->base_gfn << PAGE_SHIFT, + new->npages * PAGE_SIZE, + 0, + new->id); + } else if (change == KVM_MR_DELETE) { + uv_unregister_mem_slot(kvm->arch.lpid, old->id); + } } /* diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 4efd65d9e828..3aeb17b88de7 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -1913,7 +1913,8 @@ static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm, static void kvmppc_core_commit_memory_region_pr(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, const struct kvm_memory_slot *old, - const struct kvm_memory_slot *new) + const struct kvm_memory_slot *new, + enum kvm_mr_change change) { return; } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 2869a299c4ed..6a7a6a101efd 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -696,7 +696,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, const struct kvm_memory_slot *new, enum kvm_mr_change change) { - kvmppc_core_commit_memory_region(kvm, mem, old, new); + kvmppc_core_commit_memory_region(kvm, mem, old, new, change); } void kvm_arch_flush_shadow_memslot(struct kvm *kvm,