Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10594167ybi; Thu, 11 Jul 2019 07:50:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqy25WM5JRFqJ7b9Ru82cDhnBRtKVJVtyResxqOBd2y6bYZulX+1+B4qccEsxgitBBoRWeIa X-Received: by 2002:a17:902:9a06:: with SMTP id v6mr4991428plp.71.1562856631452; Thu, 11 Jul 2019 07:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562856631; cv=none; d=google.com; s=arc-20160816; b=YmBy/edO9ss37ECY6U6Z3VzLIHem/ZCKupJO19SEe7ZzukKVOkGJLSjlOXPttL47iP GivTXg/WFHWZUWQM8Q8iIp9QoodF3FJvCPnck+JW21VW5m1ZopHWcEDGmHF8EmGLCt7W Q2cAPNb6GGemcwoBKiwsdWmZXMUeuhlemtnyG5l+fmJW5ygj4G7bZI0YeKTOQnhiTvke WhKZlxNuWvo1TDa+iJRz0dC6bpZzyK3f29id0xUtLLGmrtqS/BfnObBZ0Jv9ILc/zqY1 9oYBRTEaCz40xujVHek8M9+0orKAhakznVhd43mnvJXut3TCulpkHO1Qucn+LNC2I/1H aPEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=p0TwseF6Rl2ptej9BTwWkpZCi9Mm6El6sXWBWxSv9Wc=; b=0iJHbQmsdrCIpVFT9J+lNsyCh8U6R1KvyDFfO0/B4Ckdm9DkKNmpXAxIFNHzY/4WJm bFKOy8ybi6epv84utq4kN+Na5xE1dVNSCrz0dsKy9LCubXW/Q/nlSoCubkKPLTzMuff9 BPug+X411mCi1KaV0ccztEQVaJHF/H335QICeB9b9JGgjM3Z3gbCDCQwD8yedCxvpPGa smMTwt24AFady7Usb1jxE7Z9pZw7bfeP+mFPufnjrnVo8zkccYe/E+vZfBCTM0NcPS0X wGZkWvyR420QbKOZQIHKh1m8p5abwhWUID0E3RBbq32jGWTWGQDq4y9t0/RbTU+wWLEq NQ/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VxnBJQPS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f61si5236610plf.258.2019.07.11.07.50.16; Thu, 11 Jul 2019 07:50:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VxnBJQPS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728813AbfGKO3h (ORCPT + 99 others); Thu, 11 Jul 2019 10:29:37 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39164 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727612AbfGKO3g (ORCPT ); Thu, 11 Jul 2019 10:29:36 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6BEO8vQ001464; Thu, 11 Jul 2019 14:27:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=p0TwseF6Rl2ptej9BTwWkpZCi9Mm6El6sXWBWxSv9Wc=; b=VxnBJQPSh0LmxFyWqVND6G3imbrgiNDc2XYktPKhPxTH7jeK12iQ07uhiR7KSkYssaXb Pv64TstUQ6TZGJ1PMaSuITPpNq63mpZXM6Iv7MEPC/m1XIUd6uAVwnuCuLzWwEkJpk+d bLhzpPXWzEGxFhxH1pYNQvLU4rahHXqpvu4/IcVK0tDJMHq3A7NSNALQrgdnEe+A5MWw HjWBvSrm/StSA0wUZr133cDwxkrZIL+2nTAatg2QWIUq+pis7baTZiMjbcwkfcdkdyAy 8SJFtfEFVLR+g5pFWeVErgqD0yalSI8+c1PK8OfF5ETzFY1qWu5XfRWDWSejjFNNjfXr 8Q== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2tjk2u0e5t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Jul 2019 14:27:15 +0000 Received: from achartre-desktop.fr.oracle.com (dhcp-10-166-106-34.fr.oracle.com [10.166.106.34]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x6BEPcuJ021444; Thu, 11 Jul 2019 14:27:06 GMT From: Alexandre Chartre To: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, kvm@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: konrad.wilk@oracle.com, jan.setjeeilers@oracle.com, liran.alon@oracle.com, jwadams@google.com, graf@amazon.de, rppt@linux.vnet.ibm.com, alexandre.chartre@oracle.com Subject: [RFC v2 26/26] KVM: x86/asi: Map KVM memslots and IO buses into KVM ASI Date: Thu, 11 Jul 2019 16:25:38 +0200 Message-Id: <1562855138-19507-27-git-send-email-alexandre.chartre@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1562855138-19507-1-git-send-email-alexandre.chartre@oracle.com> References: <1562855138-19507-1-git-send-email-alexandre.chartre@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9314 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907110162 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Map KVM memslots and IO buses into KVM ASI. Mapping is checking on each KVM ASI enter because they can change. Signed-off-by: Alexandre Chartre --- arch/x86/kvm/x86.c | 36 +++++++++++++++++++++++++++++++++++- include/linux/kvm_host.h | 2 ++ 2 files changed, 37 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9458413..7c52827 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7748,11 +7748,45 @@ void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu) static void vcpu_isolation_enter(struct kvm_vcpu *vcpu) { - int err; + struct kvm *kvm = vcpu->kvm; + struct kvm_io_bus *bus; + int i, err; if (!vcpu->asi) return; + /* + * Check memslots and buses mapping as they tend to change. + */ + for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { + if (vcpu->asi_memslots[i] == kvm->memslots[i]) + continue; + pr_debug("remapping kvm memslots[%d]: %px -> %px\n", + i, vcpu->asi_memslots[i], kvm->memslots[i]); + err = asi_remap(vcpu->asi, &vcpu->asi_memslots[i], + kvm->memslots[i], sizeof(struct kvm_memslots)); + if (err) { + pr_debug("failed to map kvm memslots[%d]: error %d\n", + i, err); + } + } + + + for (i = 0; i < KVM_NR_BUSES; i++) { + bus = kvm->buses[i]; + if (bus == vcpu->asi_buses[i]) + continue; + pr_debug("remapped kvm buses[%d]: %px -> %px\n", + i, vcpu->asi_buses[i], bus); + err = asi_remap(vcpu->asi, &vcpu->asi_buses[i], bus, + sizeof(*bus) + bus->dev_count * + sizeof(struct kvm_io_range)); + if (err) { + pr_debug("failed to map kvm buses[%d]: error %d\n", + i, err); + } + } + err = asi_enter(vcpu->asi); if (err) pr_debug("KVM isolation failed: error %d\n", err); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2a9d073..1f82de4 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -324,6 +324,8 @@ struct kvm_vcpu { #ifdef CONFIG_ADDRESS_SPACE_ISOLATION struct asi *asi; + void *asi_memslots[KVM_ADDRESS_SPACE_NUM]; + void *asi_buses[KVM_NR_BUSES]; #endif }; -- 1.7.1