From patchwork Tue Apr 19 13:39:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 8880261 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E45D09F1C1 for ; Tue, 19 Apr 2016 13:44:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E32E9200E6 for ; Tue, 19 Apr 2016 13:44:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 02ACC20211 for ; Tue, 19 Apr 2016 13:44:39 +0000 (UTC) Received: from localhost ([::1]:58171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVxG-0004Xm-EA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Apr 2016 09:44:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsi-0003YL-1K for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asVsd-0000i1-P1 for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:55 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsd-0000hv-F4 for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:51 -0400 Received: by mail-wm0-x242.google.com with SMTP id n3so5310695wmn.1 for ; Tue, 19 Apr 2016 06:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=os+7STLUOZnJYmId5Q3qlXz/RI8oGriM2vJ6rX+XZ98=; b=O/tJft2gK4AWayfpA5lFnUKMF6Kb62ywJagad9arVulIt6YClHR536f74qNwe7J1ym hrQmgb0uDDVn8nF+ApAhp/cUxRvKD/JwlCMVsAl3XItzAhB5gRDBv1KUOZIolUx98+GV ebDdWS5q1Tax03ieR3fHyF/oszFpw5bTwNAqKJX/H06U15dUNBAxJIFyrtI5dgUVNnZP r1kTKr58PeJT4Kjl8pDtG6UodVKciEgBa5CNqOEjr3EcPQtL1VCwPEmERd6mjAiwuEdb dqJqEbFlkF2EX/E4PqF+StvlFZrpKA0o3zF3SHpJDN/HgcmaBkNPb+bQYrva5Zd02nvR g30Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=os+7STLUOZnJYmId5Q3qlXz/RI8oGriM2vJ6rX+XZ98=; b=PAcsmXqwGY07yhw1VAQrs8jg2ANntnBmV+JeCCoa2yFeV6EO1E66O0xLbbaC6vsb7f kClrLdo12FFUw2OEgbnxGGRffQXzDPkfdsjGChGyOdxk9Ha/eH7IsRZ6XWiHWpPcZn9a 3ScFkzdPgG7nfLTcmx9ZyNOlXPTEmwmX2WPq7NWmdraX0pFutguljoT+1BU+39WYP8rc fYohHn0/Ewk89LMHKj53sufStQdyAFbG/SD+7RY9ZyUC9xJtoBi2BJNsKhqsTkpYT7ji l/pN2K4D+8kYUClAXfjaoNp4PcYFqmcwzSVo+ioyDaRLmfNQHXVgXOTsHp43rPEt0Qy0 4j3A== X-Gm-Message-State: AOPr4FXcdIynx4Q/gf+Dr82XPAGRjlKCAyFn+9CXUJq/OZ5ASi1tGwDEj64sz03qFz5ELw== X-Received: by 10.28.54.70 with SMTP id d67mr25995143wma.94.1461073190857; Tue, 19 Apr 2016 06:39:50 -0700 (PDT) Received: from localhost.localdomain (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id c85sm2789756wmd.0.2016.04.19.06.39.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 06:39:50 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Date: Tue, 19 Apr 2016 15:39:26 +0200 Message-Id: <1461073171-22953-10-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461073171-22953-1-git-send-email-a.rigo@virtualopensystems.com> References: <1461073171-22953-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [RFC v8 09/14] softmmu: Honor the new exclusive bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Crosthwaite , claudio.fontana@huawei.com, Alvise Rigo , serge.fdrv@gmail.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The pages set as exclusive (clean) in the DIRTY_MEMORY_EXCLUSIVE bitmap have to have their TLB entries flagged with TLB_EXCL. The accesses to pages with TLB_EXCL flag set have to be properly handled in that they can potentially invalidate an open LL/SC transaction. Modify the TLB entries generation to honor the new bitmap and extend the softmmu_template to handle the accesses made to guest pages marked as exclusive. The TLB_EXCL flag is used only for normal RAM memory. Exclusive accesses to MMIO memory are still not supported, but they will with the next patch. Suggested-by: Jani Kokkonen Suggested-by: Claudio Fontana Signed-off-by: Alvise Rigo --- cputlb.c | 36 ++++++++++++++++++++++++++---- softmmu_template.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 89 insertions(+), 12 deletions(-) diff --git a/cputlb.c b/cputlb.c index 02b0d14..e5df3a5 100644 --- a/cputlb.c +++ b/cputlb.c @@ -416,11 +416,20 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, || memory_region_is_romd(section->mr)) { /* Write access calls the I/O callback. */ te->addr_write = address | TLB_MMIO; - } else if (memory_region_is_ram(section->mr) - && cpu_physical_memory_is_clean(section->mr->ram_addr - + xlat)) { - te->addr_write = address | TLB_NOTDIRTY; } else { + if (memory_region_is_ram(section->mr) + && cpu_physical_memory_is_clean(section->mr->ram_addr + + xlat)) { + address |= TLB_NOTDIRTY; + } + /* Only normal RAM accesses need the TLB_EXCL flag to handle + * exclusive store operatoins. */ + if (!(address & TLB_MMIO) && + cpu_physical_memory_is_excl(section->mr->ram_addr + xlat)) { + /* There is at least one vCPU that has flagged the address as + * exclusive. */ + address |= TLB_EXCL; + } te->addr_write = address; } } else { @@ -496,6 +505,25 @@ static inline void excl_history_put_addr(hwaddr addr) excl_history.c_array[excl_history.last_idx] = addr & TARGET_PAGE_MASK; } +/* For every vCPU compare the exclusive address and reset it in case of a + * match. Since only one vCPU is running at once, no lock has to be held to + * guard this operation. */ +static inline void reset_other_cpus_colliding_ll_addr(hwaddr addr, hwaddr size) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + if (current_cpu != cpu && + cpu->excl_protected_range.begin != EXCLUSIVE_RESET_ADDR && + ranges_overlap(cpu->excl_protected_range.begin, + cpu->excl_protected_range.end - + cpu->excl_protected_range.begin, + addr, size)) { + cpu->excl_protected_range.begin = EXCLUSIVE_RESET_ADDR; + } + } +} + #define MMUSUFFIX _mmu /* Generates LoadLink/StoreConditional helpers in softmmu_template.h */ diff --git a/softmmu_template.h b/softmmu_template.h index ede1240..2934a0c 100644 --- a/softmmu_template.h +++ b/softmmu_template.h @@ -469,6 +469,43 @@ static inline void smmu_helper(do_ram_store)(CPUArchState *env, #endif } +static inline void smmu_helper(do_excl_store)(CPUArchState *env, + bool little_endian, + DATA_TYPE val, target_ulong addr, + TCGMemOpIdx oi, int index, + uintptr_t retaddr) +{ + CPUIOTLBEntry *iotlbentry = &env->iotlb[get_mmuidx(oi)][index]; + CPUState *cpu = ENV_GET_CPU(env); + CPUClass *cc = CPU_GET_CLASS(cpu); + /* The slow-path has been forced since we are writing to + * exclusive-protected memory. */ + hwaddr hw_addr = (iotlbentry->addr & TARGET_PAGE_MASK) + addr; + + /* The function reset_other_cpus_colliding_ll_addr could have reset + * the exclusive address. Fail the SC in this case. + * N.B.: here excl_succeed == true means that the caller is + * helper_stcond_name in softmmu_llsc_template. + * On the contrary, excl_succeeded == false occurs when a VCPU is + * writing through normal store to a page with TLB_EXCL bit set. */ + if (cpu->excl_succeeded) { + if (!cc->cpu_valid_excl_access(cpu, hw_addr, DATA_SIZE)) { + /* The vCPU is SC-ing to an unprotected address. */ + cpu->excl_protected_range.begin = EXCLUSIVE_RESET_ADDR; + cpu->excl_succeeded = false; + + return; + } + } + + smmu_helper(do_ram_store)(env, little_endian, val, addr, oi, + get_mmuidx(oi), index, retaddr); + + reset_other_cpus_colliding_ll_addr(hw_addr, DATA_SIZE); + + return; +} + void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, TCGMemOpIdx oi, uintptr_t retaddr) { @@ -493,11 +530,17 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, tlb_addr = env->tlb_table[mmu_idx][index].addr_write; } - /* Handle an IO access. */ + /* Handle an IO access or exclusive access. */ if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { - smmu_helper(do_mmio_store)(env, true, val, addr, oi, mmu_idx, index, - retaddr); - return; + if (tlb_addr & TLB_EXCL) { + smmu_helper(do_excl_store)(env, true, val, addr, oi, index, + retaddr); + return; + } else { + smmu_helper(do_mmio_store)(env, true, val, addr, oi, mmu_idx, + index, retaddr); + return; + } } smmu_helper(do_ram_store)(env, true, val, addr, oi, mmu_idx, index, @@ -529,11 +572,17 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, tlb_addr = env->tlb_table[mmu_idx][index].addr_write; } - /* Handle an IO access. */ + /* Handle an IO access or exclusive access. */ if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { - smmu_helper(do_mmio_store)(env, false, val, addr, oi, mmu_idx, index, - retaddr); - return; + if (tlb_addr & TLB_EXCL) { + smmu_helper(do_excl_store)(env, false, val, addr, oi, index, + retaddr); + return; + } else { + smmu_helper(do_mmio_store)(env, false, val, addr, oi, mmu_idx, + index, retaddr); + return; + } } smmu_helper(do_ram_store)(env, false, val, addr, oi, mmu_idx, index,