Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5156561ybg; Mon, 21 Oct 2019 22:10:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqsJ9XhROJAjITPktw7KEppnqeXjFyHzj53paR8GfssNrTvv/+UN+j1h+YKJMzWbtd1Lip X-Received: by 2002:a17:906:1c87:: with SMTP id g7mr18241679ejh.189.1571721011657; Mon, 21 Oct 2019 22:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571721011; cv=none; d=google.com; s=arc-20160816; b=TMS09jIOd3DsoZ5TM/mJQYDv4PLRYFvKR9paET6LEKUYbaX++ANDowFsGZhUop+ZJ4 W9BsuuPU4Mtr522OzbrocSpBCpYRcaXqqkyYz7hgWZlP+IufUKNXOypkN0V4Ycj2tb0E QJybS1KK+b28PxOaNWC4nb1uXCk7MxuGoVhDyn2GHxcd4Q+dAdakNrMCwt2Ck/Tbk4jt k9k6ybdFUqnD3iUNslIbApWRkxyy5ZKta2b9rGshM28EvqjFjOHC8UTuA1jL0a6ZHinS V640UcA0eAI6CicDIRI1YxKsN5gbCbfS7bvhqIQWWq7dTuq2QiXX9xUxhGPu1Psr2Wxt kUiQ== 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=bTTMrmciHM4aiFMZR2LK71art6dDZteKsZ9m8QnTfYE=; b=w2Lpv2+RisQUYTBlT+foybQAJeXSN93ao1ajL1kLbiRsMuhpRSXIG4n201gLGcHRW3 BarfSD9V+3eDILeLGr5znFUUQz1RPB+IpntlW7tfX+Ov06I/gSbFOGaD/PcHwH+SLbX8 DxucK5c/vPK+Y7Kz6lnHDr9rWyL8nj195D1HYGbY7ONTDJQMBFQT/IA8SBrCdipvQdNz /5odgl1zOhmRpefpJMZ7BjDEMMkCJ367B6j5q3V/ONHZDxQhi5WZE7v0im3yQKqtbNOV wrQK7PTU0vdz/GDXIQvB0a5raDqo/IRRhngUiCeKqc7i2yEljMP9VOst5HeCZgTfJ+Oi p8Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=t5XI80Bi; 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 f29si10846577ejj.110.2019.10.21.22.09.48; Mon, 21 Oct 2019 22:10:11 -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=t5XI80Bi; 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 S1731062AbfJVFH6 (ORCPT + 99 others); Tue, 22 Oct 2019 01:07:58 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39710 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbfJVFH5 (ORCPT ); Tue, 22 Oct 2019 01:07:57 -0400 Received: by mail-wm1-f67.google.com with SMTP id r141so5188173wme.4 for ; Mon, 21 Oct 2019 22:07:55 -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=bTTMrmciHM4aiFMZR2LK71art6dDZteKsZ9m8QnTfYE=; b=t5XI80Bi4Lrln9mq+PcmKnh/yO/hMUHXGheJlgPjZHmjiOAKjNpjlwjXrH4e/9yOUp mR8jmhWjv/5OpGM8yjQhMT8lwxbmAwBue+sy9/eMu5EVFXjYnAzl3zU2VUOWqfu32NZM Z3zKuEf4f89oQkuqGUuY3+NKXqsGn82fXWfMpOdyot1HwqClZ0rZbi6horJoccoHlqBr kwilw8JQ+36mVE/vxn2gYkr710UiwpoIXu4c7yr5Z6txLx1fUYfbJjV7PbNxFvpZlrFo UqUOOHNXqgUT5BX0UdU1JbK4lADmJtAa4wyL7NBU3sCdNhXQnJrx368cQvjh4NYcUPA4 8zGQ== 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=bTTMrmciHM4aiFMZR2LK71art6dDZteKsZ9m8QnTfYE=; b=E3YiCUoxJHunWFEVn1hLJmBnpsS+1mR6cB/KrqFnxC7OAXecRwhtxYHq//xAtinwMp f9ZE20FpJUhDvjYqv+TJeUvCc+Nj4YwVGFNQtgJmCn/25kKSCMrugFWC1uxnkwlT0vlA tqNtZu2wBNm9vPvCEX4hZhUWzrmX8fJXt4JBW0630zaO6+6hlwEJKf1ru1fT36cK2CQg tQ4SkAKBuOAiwEEW6qNgkUIgBsodinwc1jy8Yw6icX314ZpzPjcoVQhc+WPKYDPkiHIM YhCfRLXh6aDxv+pCaB8Cr1bUh6vYVnBbjm/ZNZFYHz8iFBFZl31gb6pdk0n+FFOhQKeT CmyA== X-Gm-Message-State: APjAAAX8LCKV17uDqQTPJRfJpjSoiM+H92fVZOJHHjn2dqzyjF4w4No8 btvldb2ZXTEtyYozXqNnYfEQZOHMLLYL8AoFrSD5OA== X-Received: by 2002:a1c:9695:: with SMTP id y143mr1119738wmd.103.1571720874948; Mon, 21 Oct 2019 22:07:54 -0700 (PDT) MIME-Version: 1.0 References: <20191016160649.24622-1-anup.patel@wdc.com> <20191016160649.24622-21-anup.patel@wdc.com> <1d2e9514-235e-183e-b4fc-d3becc9ce471@redhat.com> In-Reply-To: <1d2e9514-235e-183e-b4fc-d3becc9ce471@redhat.com> From: Anup Patel Date: Tue, 22 Oct 2019 10:37:43 +0530 Message-ID: Subject: Re: [PATCH v9 20/22] RISC-V: KVM: Fix race-condition in kvm_riscv_vcpu_sync_interrupts() To: Paolo Bonzini Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Radim K , Daniel Lezcano , Thomas Gleixner , Alexander Graf , 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 Mon, Oct 21, 2019 at 10:57 PM Paolo Bonzini wrote: > > On 16/10/19 18:12, Anup Patel wrote: > > + /* Read current VSIP and VSIE CSRs */ > > + vsip = csr_read(CSR_VSIP); > > + csr->vsie = csr_read(CSR_VSIE); > > + > > + /* Sync-up VSIP.SSIP bit changes does by Guest */ > > + if ((csr->vsip ^ vsip) & (1UL << IRQ_S_SOFT)) { > > + if (!test_and_set_bit(IRQ_S_SOFT, &v->irqs_pending_mask)) { > > + if (vsip & (1UL << IRQ_S_SOFT)) > > + set_bit(IRQ_S_SOFT, &v->irqs_pending); > > + else > > + clear_bit(IRQ_S_SOFT, &v->irqs_pending); > > + } > > Looks good, but I wonder if this could just be "csr->vsip = > csr_read(CSR_VSIP)", which will be fixed up by flush_interrupts on the > next entry. It's not just "csr->vsip = csr_read(CSR_VSIP" because "irqs_pending" bitmap has to be in-sync with Guest updates to VSIP because WFI trap-n-emulate will check for pending interrupts which in-turn checks "irqs_pending" bitmap. Regards, Anup