Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4539425ybg; Mon, 21 Oct 2019 10:29:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyajEh3ko4VUMjpmYV5mKDwnpI6FuPaKzBFK/4ok2L7Bh2UnRHXa3T+9htqO16QnsI/ezic X-Received: by 2002:a50:af22:: with SMTP id g31mr26233245edd.199.1571678982209; Mon, 21 Oct 2019 10:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571678982; cv=none; d=google.com; s=arc-20160816; b=OBHTUCOYVzCr+zOxtxIA+5jqxLl4m8UpMnA8Z5peiiT9ex3MLdHdtx1PhCDSPm5wjK ArCgqUeHtSP2l9X0jmz0xGcegW6TJ2MP1ATGvb/tpTZcyoY3uHdvCG58XPXHl0ueoRxq BL/infJLGrUwlmz5snsXCHdjPgiBbWA+HaKa9PML1LMcsED5dD/iLp0Dv+j8sAPkvJyz BmCd+eJVz2f+bcLS05gAfa23TfpQYwQPaE9i9tXujlHlVnzE6SC4ItdFWwMANIQIpMbj WzDfJPjuO8rf3ALLbWNjiQUrqhrabEea3ajW0BqtPgue/Xp5czcb/omTH0nIEmxTAyn/ WeNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:openpgp:from:references:cc:to:subject; bh=lvbEIhN+KLA5G34KXJDqPu7aWF/7PZQEg8je+IqEmF4=; b=sN7/QN3lsSn5PHUDxL6WxNpKI9yJ4F1r6jgRh7XXatQf++BRq+sHc5Qv9RENr7IHbW lZCk7CI4ZpDdUTjki2xuC7GljPl8aNUMpCG662aYTBdcQQV0rgZ0tKuHrTsLqp1Oykzd zmeOzVLOPBjXLk+98Oe/Va6jCCiJb6XOIRMD89EM21s87GGPyymTMjHHRdQ8OGF1lF2K kuDzPOqQUwq5l8bBdhHH+dHVL24CsJhIrB8vWiewE4TIPUQ2VGyOKYiamUQr0gSw+60L kU4wihHObgfJTunjlEpN7LdU+WN4CXKD0jv9Gk9DhjnBZLu3wRyDSGQxCgcjVIHKdvJy Q8HQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ec21si8503908ejb.26.2019.10.21.10.29.17; Mon, 21 Oct 2019 10:29:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbfJUR2y (ORCPT + 99 others); Mon, 21 Oct 2019 13:28:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52098 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbfJUR2y (ORCPT ); Mon, 21 Oct 2019 13:28:54 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86EB787638 for ; Mon, 21 Oct 2019 17:28:53 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id 67so7649635wrm.18 for ; Mon, 21 Oct 2019 10:28:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lvbEIhN+KLA5G34KXJDqPu7aWF/7PZQEg8je+IqEmF4=; b=mT+oWJqyMW3kD7D+20XT8BIZsv4Nh0azOYjfG5iryn7B5ntAe2L9EOjmWFYxRnH7hA aqnAg0QYZyltVwHf7fugPthlKpWjj23CpDO6RZHJZMZlRUwecGFqtKykmLBT933PCZs/ A1RaX5TrOGAjH1SXP9ueHoUhsj1BPNFhZWnOtOmApS3NQNlTXAo5/q18cXxRERa1pOro CE7/WjATE5Nq760ym2LIAu+1arsg1oVHHiODWCI5ZVFD5s4SpcTlT61sVfu90UHAkHMQ eD4VtDYgSLOGuTsbFPdK1eQ9MjDOldhkfZ3mgDs7oLY33iSN3Qw+9fI3tJpc8FVaxx9t nn4g== X-Gm-Message-State: APjAAAVz9yHYdS+ASTUN1/gQ80pO46mBH/RzW+Qrjgz4Qtb8Y8qZ89/c UNepY97vdMTad0L4DA/KY9V7R1h5wPsJhMjLPM2gopXatj2S8LVaZ76D03bZwtwuf3M4YB676n2 mIlERFoB23V467t8CLKNo4/FY X-Received: by 2002:a7b:c019:: with SMTP id c25mr1082378wmb.61.1571678930587; Mon, 21 Oct 2019 10:28:50 -0700 (PDT) X-Received: by 2002:a7b:c019:: with SMTP id c25mr1082361wmb.61.1571678930237; Mon, 21 Oct 2019 10:28:50 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:847b:6afc:17c:89dd? ([2001:b07:6468:f312:847b:6afc:17c:89dd]) by smtp.gmail.com with ESMTPSA id a17sm12276159wrx.84.2019.10.21.10.28.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2019 10:28:49 -0700 (PDT) Subject: Re: [PATCH v9 19/22] RISC-V: KVM: Remove per-CPU vsip_shadow variable To: Anup Patel , Palmer Dabbelt , Paul Walmsley , Radim K Cc: Daniel Lezcano , Thomas Gleixner , Alexander Graf , Atish Patra , Alistair Francis , Damien Le Moal , Christoph Hellwig , Anup Patel , "kvm@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" References: <20191016160649.24622-1-anup.patel@wdc.com> <20191016160649.24622-20-anup.patel@wdc.com> From: Paolo Bonzini Openpgp: preference=signencrypt Message-ID: <7381057d-a3f3-e79a-bb2c-b078fc918b1f@redhat.com> Date: Mon, 21 Oct 2019 19:28:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191016160649.24622-20-anup.patel@wdc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/10/19 18:12, Anup Patel wrote: > Currently, we track last value wrote to VSIP CSR using per-CPU > vsip_shadow variable but this easily goes out-of-sync because > Guest can update VSIP.SSIP bit directly. > > To simplify things, we remove per-CPU vsip_shadow variable and > unconditionally write vcpu->arch.guest_csr.vsip to VSIP CSR in > run-loop. > > Signed-off-by: Anup Patel Please squash this and patch 20 into the corresponding patches earlier in the series. Paolo > --- > arch/riscv/include/asm/kvm_host.h | 3 --- > arch/riscv/kvm/main.c | 6 ------ > arch/riscv/kvm/vcpu.c | 24 +----------------------- > 3 files changed, 1 insertion(+), 32 deletions(-) > > diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h > index ec1ca4bc98f2..cd86acaed055 100644 > --- a/arch/riscv/include/asm/kvm_host.h > +++ b/arch/riscv/include/asm/kvm_host.h > @@ -202,9 +202,6 @@ static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} > static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} > static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} > > -int kvm_riscv_setup_vsip(void); > -void kvm_riscv_cleanup_vsip(void); > - > #define KVM_ARCH_WANT_MMU_NOTIFIER > int kvm_unmap_hva_range(struct kvm *kvm, > unsigned long start, unsigned long end); > diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c > index 55df85184241..002301a27d29 100644 > --- a/arch/riscv/kvm/main.c > +++ b/arch/riscv/kvm/main.c > @@ -61,17 +61,11 @@ void kvm_arch_hardware_disable(void) > > int kvm_arch_init(void *opaque) > { > - int ret; > - > if (!riscv_isa_extension_available(NULL, h)) { > kvm_info("hypervisor extension not available\n"); > return -ENODEV; > } > > - ret = kvm_riscv_setup_vsip(); > - if (ret) > - return ret; > - > kvm_riscv_stage2_vmid_detect(); > > kvm_info("hypervisor extension available\n"); > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c > index fd77cd39dd8c..f1a218d3a8cf 100644 > --- a/arch/riscv/kvm/vcpu.c > +++ b/arch/riscv/kvm/vcpu.c > @@ -111,8 +111,6 @@ static void kvm_riscv_vcpu_host_fp_restore(struct kvm_cpu_context *cntx) {} > riscv_isa_extension_mask(s) | \ > riscv_isa_extension_mask(u)) > > -static unsigned long __percpu *vsip_shadow; > - > static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) > { > struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; > @@ -765,7 +763,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > { > struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; > - unsigned long *vsip = raw_cpu_ptr(vsip_shadow); > > csr_write(CSR_VSSTATUS, csr->vsstatus); > csr_write(CSR_VSIE, csr->vsie); > @@ -775,7 +772,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > csr_write(CSR_VSCAUSE, csr->vscause); > csr_write(CSR_VSTVAL, csr->vstval); > csr_write(CSR_VSIP, csr->vsip); > - *vsip = csr->vsip; > csr_write(CSR_VSATP, csr->vsatp); > > kvm_riscv_stage2_update_hgatp(vcpu); > @@ -843,26 +839,8 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) > static void kvm_riscv_update_vsip(struct kvm_vcpu *vcpu) > { > struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; > - unsigned long *vsip = raw_cpu_ptr(vsip_shadow); > - > - if (*vsip != csr->vsip) { > - csr_write(CSR_VSIP, csr->vsip); > - *vsip = csr->vsip; > - } > -} > - > -int kvm_riscv_setup_vsip(void) > -{ > - vsip_shadow = alloc_percpu(unsigned long); > - if (!vsip_shadow) > - return -ENOMEM; > > - return 0; > -} > - > -void kvm_riscv_cleanup_vsip(void) > -{ > - free_percpu(vsip_shadow); > + csr_write(CSR_VSIP, csr->vsip); > } > > int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) >