Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp686598ybi; Fri, 2 Aug 2019 02:36:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXYaXWuSMya1xBgpYXPI3OLpl1DG0Gvi8VLNko6c/dQBEvo3PJlVc18KdKFMR8tC6eulzV X-Received: by 2002:a17:90a:228b:: with SMTP id s11mr3397359pjc.23.1564738604805; Fri, 02 Aug 2019 02:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564738604; cv=none; d=google.com; s=arc-20160816; b=BHLj63FDywC3iavaGa4NHH9cwpX+zIFkeHbmqQJPJKXR8jeGdY0lngRkxRKTU3veP1 Bs5mOr3QN94rklTcq2xmfinxtsEWY7N6Xs/blf7cXpiL+cvkiH+egml6UX90UWXi0EZm 9Im/5LvkZtjDitS8D3FzZGiEewVC5M8ok6Pf8JPAgyKN6Qbyg+MGz5DAVeq0B1YC0h/W Isx8diE2PmUDLvpojPT7SK1iPR+Fo2ozFRi3rwrszJ+vK7bO+q8Ms46FOsL4nw8Jyc/t HmHOkBexlGqQdn+qcqw9JWGJLxBfaNkWOtFjBy2tEgGn/G5s5f3LIn9y4NMhzlSgadN5 spKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4fvZtEUHzSAKzVrV5AOyqmz39HB0VJQNW+QYwyaRSP8=; b=b9+W6j5Kyv9dpJNwyzb+3QmRuNv+AYuaMCiG2+G5yycDP7ly/RpRuyZ9YzFBjqR9RH EAgDRXcoyeAcwYLVOK+ayiJdhn0BIapweANQV4tyfpQW/tQpgurgpcbmwiazCbr9zBBl ni+MK8fLfzYFJ2KVgZjsLqTwNmuHeQfTnvA9u9OcrmGd7xOBqCLGssgHqr6AiJ9m73ZC 7K8dPPEjQNzrx4fw9MDkXyP+JVxFLqMaY9EFZtxoG1RTZia4Furd27Zqx/G7oKxcQ5wL 2LDElYZUio/sKEG3LyX3YuEyLcgJcqdl0wl+OjdprUc66f19KE6xyOSrWJdWi8bR+bjy NBkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=eVWg8TPm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si41240304pfg.260.2019.08.02.02.36.28; Fri, 02 Aug 2019 02:36:44 -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=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=eVWg8TPm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404411AbfHBIoF (ORCPT + 99 others); Fri, 2 Aug 2019 04:44:05 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40277 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfHBIoF (ORCPT ); Fri, 2 Aug 2019 04:44:05 -0400 Received: by mail-wr1-f67.google.com with SMTP id r1so76271675wrl.7 for ; Fri, 02 Aug 2019 01:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4fvZtEUHzSAKzVrV5AOyqmz39HB0VJQNW+QYwyaRSP8=; b=eVWg8TPmTdTRpDNDCOsjC4/KOvtHtbA59TBmQpqBTpEAcbGe1sHWV9Ml4O0/GHWjIC TIk0QMnDFaqET3emtRhSQaQHsG2RAbId4A2KPGGTXL7s29NqSW0K7GhCoMcmZ+KZ8dKI PwC6FuSYrrbGPGJf7mkFuicfKeymU78FbY7saknYYNLWo+vqWdXIxb2vNEl+c/oSo1vJ D72TyjVS2XCILOUSIqknYw+d+6Lri7hcad32mztop9cmXfd93VlHjoizzJNNbHW94HmX c5BZ/dtEwOAoDlwI85Byw8UHZh49hT1dy6qXDhYaW/bYdZh16X7zSNGwUAWBPXZVo3k4 lV6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4fvZtEUHzSAKzVrV5AOyqmz39HB0VJQNW+QYwyaRSP8=; b=fN1CKO0LT0zpLZLx+N9qIlZ1zXUf6RBS7yR8REUZQN1FXyQMj4hET7YzysIfnNaNkt 5pFsgg6rygZMaEoFSEUCw2aTS+uNvzQw2OfHThVp5gDXuj5rfSFudZvo26qerDbJdKwi sO8R0OUBcrdlxnpDi833fRFpAmh63AvcmZOAKOrIR9D4D68OYVpcxCIry5enR24oR+tQ ySV17t4fOcx61IbXNh50c5qB1PMpdC3gYZfoipZDXui/k4rtPliFSjmRr08ITV6VVbOn iCtDlbbtqRLZp2pQ99OUv2Wz6YNVRBVExI9sCkVdqUd3sJTPH5rFOXT6tpqdHGQm6/x+ 0RUg== X-Gm-Message-State: APjAAAU2V5+IgeYsJGW9JiLj2B8Dx3ZNEmN3NLDpzqxufF7X8Rc8c0jf TT2cY652zng/NFo+oviDJ6JJSQatW+8q6zCfcRE= X-Received: by 2002:adf:b1cb:: with SMTP id r11mr136837207wra.328.1564735442789; Fri, 02 Aug 2019 01:44:02 -0700 (PDT) MIME-Version: 1.0 References: <20190802074620.115029-1-anup.patel@wdc.com> <20190802074620.115029-9-anup.patel@wdc.com> <72d8efbf-ec62-ab1e-68bf-e0c5f0bc256e@redhat.com> In-Reply-To: <72d8efbf-ec62-ab1e-68bf-e0c5f0bc256e@redhat.com> From: Anup Patel Date: Fri, 2 Aug 2019 14:13:52 +0530 Message-ID: Subject: Re: [RFC PATCH v2 08/19] RISC-V: KVM: Implement VCPU world-switch To: Paolo Bonzini Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Radim K , Daniel Lezcano , Thomas Gleixner , Atish Patra , Alistair Francis , Damien Le Moal , Christoph Hellwig , "kvm@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 2, 2019 at 2:00 PM Paolo Bonzini wrote: > > On 02/08/19 09:47, Anup Patel wrote: > > + /* Save Host SSTATUS, HSTATUS, SCRATCH and STVEC */ > > + csrr t0, CSR_SSTATUS > > + REG_S t0, (KVM_ARCH_HOST_SSTATUS)(a0) > > + csrr t1, CSR_HSTATUS > > + REG_S t1, (KVM_ARCH_HOST_HSTATUS)(a0) > > + csrr t2, CSR_SSCRATCH > > + REG_S t2, (KVM_ARCH_HOST_SSCRATCH)(a0) > > + csrr t3, CSR_STVEC > > + REG_S t3, (KVM_ARCH_HOST_STVEC)(a0) > > + > > A possible optimization: if these cannot change while Linux runs (I am > thinking especially of STVEC and HSTATUS, but perhaps SSCRATCH can be > saved on kvm_arch_vcpu_load too) you can avoid the csrr and store. Actual exception vector of Host Linux is different so we switch STVEC every time. HSTATUS.SPV is set whenever we come back from Guest world so while we are in in-kernel run loop with interrupts enabled we can get external interrupt and HSTATUS.SPV bit can affect SRET of interrupt handler. To handle this we switch HSTATUS every time. The world switch code uses SSCRATCH to save vcpu->arch pointer which is later used on return path. Now, I did not want to restrict Host Linux from using SSCRATCH for some other purpose hence we switch SSCRATCH every time. Regards, Anup