From patchwork Wed Nov 21 05:28:10 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: 10691985 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 3F57C5A4 for ; Wed, 21 Nov 2018 05:29:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D8312B33B for ; Wed, 21 Nov 2018 05:29:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E22B2B342; Wed, 21 Nov 2018 05:29:14 +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 7B91D2B33B for ; Wed, 21 Nov 2018 05:29:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92F4D6B2447; Wed, 21 Nov 2018 00:29:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 904606B2448; Wed, 21 Nov 2018 00:29:12 -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 7CDD86B2449; Wed, 21 Nov 2018 00:29:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 220816B2447 for ; Wed, 21 Nov 2018 00:29:12 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id x15so2468893edd.2 for ; Tue, 20 Nov 2018 21:29:12 -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=ULHIgucI09kfv+alwXLIEFOjA7hxYdxi5iwYdgrosh4=; b=KEpFk8rJlPSZlOa7IYNRYhKy/RrqWlyGWfKXwWuFNy+ZCdc59RJOZm2RwHGdVgcOUB 0aUFKIZozAXjy0Wn2h9Gk8/KDHN+/UPusKuUTbB5kvjnceLsoxXaS6stQQlKePjs/+iU 7pQhFDfXi4n3YLaZ/pIbkkrCP8HfcxTusNegul+SKwfCekq38zkQMEv5trmTysduRC0T sIFLDixotc89C5jlI3rT3iiZVj3Mn2s/UoQ5F5YHj8FnEl6edTFGy3gFPQ5V0StWXHS0 dJBIosebbvvNcZ+OuXqQqtFwzc1yFsNLFalPd+wdgfd6tOxLQQnWbY5BLtJT3Cg+ZEm+ TcRg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.158.5 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+aEWaXB4+gAiss/mZ76ToKgIXKT+2WAGxa3QSbEI1qgdvOia8RFTRr FcvYBha499AQ+2U4jCLspLN0juNdMQfBmT+zgVURj5n9pzqvKGVuXiiDso9gY+S7VVNbODD5Zkn 6jOivq9kL7hbH3hTavXWdXKEBOi8zuE9HRZwZJY3x/qQGU1NFRvxX+CiZefYR3ERj/w== X-Received: by 2002:a50:b31c:: with SMTP id q28mr4418575edd.241.1542778151651; Tue, 20 Nov 2018 21:29:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/UadDsXAllxDdPSDh44pckILOu9pMQs089NuRDc0mvNzqfrwmAk2uRsOaVCGfnuWRRhfa8z X-Received: by 2002:a50:b31c:: with SMTP id q28mr4418515edd.241.1542778150218; Tue, 20 Nov 2018 21:29:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542778150; cv=none; d=google.com; s=arc-20160816; b=T4GYktmXTqXz+pMR6az4NpMbFbaJsVtIBKMiBHDk14OyorjZY9c+EWoxVhaxN0Cq3u zcR39hLCEWeHnWCi7ceMtWZpFGXBYtdVUfW+/RqWO0AaUFQYioKslm9+8ReERYL88vYi CQ5sxqj78AJ0zaQhnICc1pu6zwyvVr7LqdfsDW6lcVHlnBWPq1Pl6qsOR7fnYRb2tk5w EldUJX8t3RkH2qr9UlFk7W6dmvD2nQX7hKe2dGp8WuDQ90r6zVpveeqzZg87jug4uKO8 X4w2mCPQ7yDnFLdGYQzpyxLNiomPDInErfn5eboGPg6O9DPFDp0ErTkoJ2+zdGwrBYUH Fgxw== 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=ULHIgucI09kfv+alwXLIEFOjA7hxYdxi5iwYdgrosh4=; b=xWEvck4jT4a0T1+phppVegBWLQo5FhzRooPK2i6MFvPCMNEwiNYd5YFqJdsR7X7LNX GPu5UHn/7IVi3TP059DV2myejytprIH2qAJsXguPy9BogGJXiZdajsdIiUWcHA6L41eA YfTKmXFPjhSjt0bwuz2g8j0kDSwuo3VuR4/frqtQ1Oap2xFdhgFrVelq/5ikliBgYDQ2 IvnKlMDzQoHelKY7xCdsMa86sOXldJvAgpAzDMML3z+HFyq5Nie87bkooEYh9gsfMKLS RRpDShMYR0G6kSzsMRB+1TyGWBYE/1t0uFn4j/agffl7HcLDd2ouEj7PQDig4zz2abr9 5JZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.158.5 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 (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id p3si247577edx.140.2018.11.20.21.29.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 21:29:10 -0800 (PST) Received-SPF: pass (google.com: domain of bharata@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of bharata@linux.ibm.com designates 148.163.158.5 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 (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAL5T7a4031146 for ; Wed, 21 Nov 2018 00:29:08 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2nw001tchd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 21 Nov 2018 00:29:08 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Nov 2018 05:28:28 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) 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:25 -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 wAL5SORt7078256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 21 Nov 2018 05:28:24 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 211A64C044; Wed, 21 Nov 2018 05:28:24 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 92AAC4C04A; Wed, 21 Nov 2018 05:28:22 +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:22 +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 3/4] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls Date: Wed, 21 Nov 2018 10:58:10 +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-0020-0000-0000-000002EB47BD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112105-0021-0000-0000-0000213A7D4A Message-Id: <20181121052811.4819-4-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=837 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 H_SVM_INIT_START: Initiate securing a VM H_SVM_INIT_DONE: Conclude securing a VM During early guest init, these hcalls will be issued by UV. As part of these hcalls, [un]register memslots with UV. Signed-off-by: Bharata B Rao --- arch/powerpc/include/asm/hvcall.h | 2 ++ arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/kvm_ppc.h | 12 ++++++++++ arch/powerpc/include/asm/ucall-api.h | 6 +++++ arch/powerpc/kvm/book3s_hv.c | 6 +++++ arch/powerpc/kvm/book3s_hv_hmm.c | 33 ++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+) diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h index 34791c627f87..4872b044cca8 100644 --- a/arch/powerpc/include/asm/hvcall.h +++ b/arch/powerpc/include/asm/hvcall.h @@ -342,6 +342,8 @@ /* Platform-specific hcalls used by the Ultravisor */ #define H_SVM_PAGE_IN 0xFF00 #define H_SVM_PAGE_OUT 0xFF04 +#define H_SVM_INIT_START 0xFF08 +#define H_SVM_INIT_DONE 0xFF0C /* Values for 2nd argument to H_SET_MODE */ #define H_SET_MODE_RESOURCE_SET_CIABR 1 diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 729bdea22250..174aa7e30ff7 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -296,6 +296,7 @@ struct kvm_arch { struct dentry *htab_dentry; struct dentry *radix_dentry; struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */ + bool secure; /* Indicates H_SVM_INIT_START has been called */ #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE struct mutex hpt_mutex; diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 659c80982497..5f4b6a73789f 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -919,6 +919,8 @@ extern unsigned long kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, unsigned long flags, unsigned long page_shift); +extern unsigned long kvmppc_h_svm_init_start(struct kvm *kvm); +extern unsigned long kvmppc_h_svm_init_done(struct kvm *kvm); #else static inline unsigned long kvmppc_h_svm_page_in(struct kvm *kvm, unsigned int lpid, @@ -935,5 +937,15 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned int lpid, { return H_UNSUPPORTED; } + +static inline unsigned long kvmppc_h_svm_init_start(struct kvm *kvm) +{ + return H_UNSUPPORTED; +} + +static inline unsigned long kvmppc_h_svm_init_done(struct kvm *kvm) +{ + return H_UNSUPPORTED; +} #endif #endif /* __POWERPC_KVM_PPC_H__ */ diff --git a/arch/powerpc/include/asm/ucall-api.h b/arch/powerpc/include/asm/ucall-api.h index a84dc2abd172..347637995b1b 100644 --- a/arch/powerpc/include/asm/ucall-api.h +++ b/arch/powerpc/include/asm/ucall-api.h @@ -19,4 +19,10 @@ static inline int uv_page_out(u64 lpid, u64 dst_ra, u64 src_gpa, u64 flags, return U_SUCCESS; } +static inline int uv_register_mem_slot(u64 lpid, u64 start_gpa, u64 size, + u64 flags, u64 slotid) +{ + return 0; +} + #endif /* _ASM_POWERPC_UCALL_API_H */ diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 7e413605e7c4..d7aa85330016 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1006,6 +1006,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) kvmppc_get_gpr(vcpu, 6), kvmppc_get_gpr(vcpu, 7)); break; + case H_SVM_INIT_START: + ret = kvmppc_h_svm_init_start(vcpu->kvm); + break; + case H_SVM_INIT_DONE: + ret = kvmppc_h_svm_init_done(vcpu->kvm); + break; default: return RESUME_HOST; diff --git a/arch/powerpc/kvm/book3s_hv_hmm.c b/arch/powerpc/kvm/book3s_hv_hmm.c index 2730ab832330..e138b0edee9f 100644 --- a/arch/powerpc/kvm/book3s_hv_hmm.c +++ b/arch/powerpc/kvm/book3s_hv_hmm.c @@ -55,6 +55,39 @@ struct kvmppc_hmm_migrate_args { unsigned long page_shift; }; +unsigned long kvmppc_h_svm_init_start(struct kvm *kvm) +{ + struct kvm_memslots *slots; + struct kvm_memory_slot *memslot; + int ret = H_SUCCESS; + int srcu_idx; + + srcu_idx = srcu_read_lock(&kvm->srcu); + slots = kvm_memslots(kvm); + kvm_for_each_memslot(memslot, slots) { + ret = uv_register_mem_slot(kvm->arch.lpid, + memslot->base_gfn << PAGE_SHIFT, + memslot->npages * PAGE_SIZE, + 0, memslot->id); + if (ret < 0) { + ret = H_PARAMETER; /* TODO: proper retval */ + goto out; + } + } + kvm->arch.secure = true; +out: + srcu_read_unlock(&kvm->srcu, srcu_idx); + return ret; +} + +unsigned long kvmppc_h_svm_init_done(struct kvm *kvm) +{ + if (kvm->arch.secure) + return H_SUCCESS; + else + return H_UNSUPPORTED; +} + #define KVMPPC_PFN_HMM (0x1ULL << 61) static inline bool kvmppc_is_hmm_pfn(unsigned long pfn)