Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2380978ybh; Sun, 4 Aug 2019 23:56:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSmKY8b3ybzTTWWtfdcWXenf1sH+KOdkwPlV/71z481ZBjl2rSAXBzt03gvicBYN+Ad80H X-Received: by 2002:a63:f04:: with SMTP id e4mr131547385pgl.38.1564988195180; Sun, 04 Aug 2019 23:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564988195; cv=none; d=google.com; s=arc-20160816; b=XzICT8Li80IZXL3zsQj68P9asDSq07whUg+B1KXoBIwLu02eyuwLvr9lZiYBe4XsGf HgmCITKRsg41Yv2dHwsHgjXqj/Il3B6nxNZ8XR0Z81FF9K+2xl3ditrR8RDjGkAa5oZY yGd+6JHnPoDhsbAmB6DWuh0lPUAT1UxxocUgYtX0ZMvgJK2q44mRd0cKwnfzqqxwKHZE pNNjUyVY+NApzmWZjsZmISkwXGCYzXcFH7CLis2WTy7wag5vlL18MPGYdl2Hkc5Umn2P kSFXd0pqExk5ebIcC0WRDNXJHeUjpeCl3Jn7Ch5iF1scRNRmejC1EXpBPMUOKW58Pydl +7ow== 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=4TTBYe7R89ObYhNrQ7Cl1PDjf+qeeSySCDSm/yvi8hE=; b=gzNsqtsk+XFYoPKxtK2+vG7glnpfggF20asJj9+LW+7fvDwge8GeWlUBXp6hPGSgHH ON28pHOcc/RFyU4JIM6RpVmjF1WjS6ZBKkxjso5mUiwvIpxqio0C9Y9UK1ig0p8UPc9z nVh/a/dQaKmejVM+6S0QsG6bD2AlrGGrjHZFiqV6zqJkhXkNEhTXO9t7rFxAqPdK/m6U PjFlqPHivw5QOwdrFgkD7UVsk+CTRIwRvw/JvlxFhpiRIRb2V8wetklfozpgPCDR1d4v MeYgtKN+JFok2v2I/DnJ3zmFBHL62TDzhER7tjcEniYMmoMoZYQNWidtXok4cNGM0Ioo gHOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=ZW+9EsnP; 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 c22si39218369plz.361.2019.08.04.23.56.19; Sun, 04 Aug 2019 23:56:35 -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=ZW+9EsnP; 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 S1727422AbfHEGze (ORCPT + 99 others); Mon, 5 Aug 2019 02:55:34 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40698 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbfHEGze (ORCPT ); Mon, 5 Aug 2019 02:55:34 -0400 Received: by mail-wr1-f66.google.com with SMTP id r1so83151298wrl.7 for ; Sun, 04 Aug 2019 23:55:32 -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=4TTBYe7R89ObYhNrQ7Cl1PDjf+qeeSySCDSm/yvi8hE=; b=ZW+9EsnPgnlzTYewisjxT+EOSy6r2aUxK55FB/Fm+mi+AtDooHD4mu+yQ4gb37M10g NFW40A+O1T6r5RXaZM/8SExP8R6DwkNY4tOg66IuS30k7+H4zGVIjXQc5CsCiFM2+BMe V0+mlrOMXhxPEG24hqd84dDo9gu3cphW0r9/JFlKTTaR+vGq0uS9aklZTp2Wcx8DcdRa 2kuzuR1HDGS6PxOG/Lzvo154FcmiWh5jjA0bm9vC2WXhhhOramW5aZIV01jvhSj2rdDM n+kO58hpipZI6NalfKRWflgcGxRn2DNY40LLNgm/sPPLUvZwPDy7XRixemaSGUe+O/Df PYaQ== 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=4TTBYe7R89ObYhNrQ7Cl1PDjf+qeeSySCDSm/yvi8hE=; b=LUiZI/W9xldoFRoycXs8UU4NKa9V5eJ2PHd8qA3IJALIoulLkwoIOqL43eoi+PsuMy tFRK8vWfGbFBnxYlO62wbn9eC+cVvw75nMPAW6zAkHNrpbDDHAeyYdHdXoKIDWeYVasr f5Ia3N5sPswnhxL8v2YkyrKycR/Oat+F/shcrNoGFj+1p7+8cryTX7GA55/CCLB5GjDO 7minWESKoLOgodxKoaxszFSXvJXKwi6fW2XmBQpoVGRReasmlEXVHk9wa5KEdBHhsHEQ 1tDeWrrFetJS8LpxgrzGbVIXaha7TMNQ++q2RhP4FR/1x5Ru3sUFtZaklCzs3aBRzDBm nKQw== X-Gm-Message-State: APjAAAUQf0yskc37vZ3ZcrFGsuWmsZJ9nwN6BpPafHyoDNx2PzEty63u IaZf3nshwj/G0/0k+WA3Nnv5OiNukjVpqwiDotE= X-Received: by 2002:adf:b1cb:: with SMTP id r11mr150790179wra.328.1564988131513; Sun, 04 Aug 2019 23:55:31 -0700 (PDT) MIME-Version: 1.0 References: <20190802074620.115029-1-anup.patel@wdc.com> <20190802074620.115029-8-anup.patel@wdc.com> <03f60f3a-bb50-9210-8352-da16cca322b9@redhat.com> In-Reply-To: <03f60f3a-bb50-9210-8352-da16cca322b9@redhat.com> From: Anup Patel Date: Mon, 5 Aug 2019 12:25:20 +0530 Message-ID: Subject: Re: [RFC PATCH v2 07/19] RISC-V: KVM: Implement KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls 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:33 PM Paolo Bonzini wrote: > > On 02/08/19 09:47, Anup Patel wrote: > > + if (reg_num == KVM_REG_RISCV_CSR_REG(sip)) > > + kvm_riscv_vcpu_flush_interrupts(vcpu, false); > > Not updating the vsip CSR here can cause an interrupt to be lost, if the > next call to kvm_riscv_vcpu_flush_interrupts finds a zero mask. Thanks for catching this issue. I will address it in v3. If we think more on similar lines then we also need to handle the case where Guest VCPU had pending interrupts and we suddenly stopped it for Guest migration. In this case, we would eventually use SET_ONE_REG ioctl on destination Host which should set vsip_shadow instead of vsip so that we force update HW after resuming Guest VCPU on destination host. > > You could add a new field vcpu->vsip_shadow that is updated every time > CSR_VSIP is written (including kvm_arch_vcpu_load) with a function like > > void kvm_riscv_update_vsip(struct kvm_vcpu *vcpu) > { > if (vcpu->vsip_shadow != vcpu->arch.guest_csr.vsip) { > csr_write(CSR_VSIP, vcpu->arch.guest_csr.vsip); > vcpu->vsip_shadow = vcpu->arch.guest_csr.vsip; > } > } > > And just call this unconditionally from kvm_vcpu_ioctl_run. The cost is > just a memory load per VS-mode entry, it should hardly be measurable. > I think we can do this at start of kvm_riscv_vcpu_flush_interrupts() as well. Regards, Anup