Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2778302rwi; Fri, 21 Oct 2022 07:50:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OT1rJBNK1sJaVuqfDLffCv9E5LIpwTdarEZ1VzrHkoOuF36riaC1mTu9idtz8nyl5+fkx X-Received: by 2002:a17:907:70a:b0:741:78ab:dce5 with SMTP id xb10-20020a170907070a00b0074178abdce5mr16087790ejb.527.1666363820487; Fri, 21 Oct 2022 07:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666363820; cv=none; d=google.com; s=arc-20160816; b=xZZt+3mP4Ujs5t9mGyJxEEtsL3u22cDZ9aAEiyuaa7+FXITQW0L0C5z9tqbLMHfsuE I/UGuK72pTy97O77/kweXq1T6yPQKVWO62LWmV+f4g5GefQVc2YKjZ/cP3RTZKU62aVk ydjLa9A9l/ArfEs+2+IcWDVej1NWIRZesc14qmaWRZ7Igx6F0WFEpet9SCZhjj24n54Z XaqaJOxyOwbB401xEOmMy+ako+7NkJ+4vcN14Pq31PevQeu50ssR4CUgQv3MCzYl6WPR eXg2lzPH4AAlETLtKNBwJf5lXoTmBNZmiSMV/Bo/Yrf3kRDWgciqypQjv73Rs4SXLDa8 S+rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3wtplGSCK47JGXL05rihD2QEaSH0/bTXL400lCGjiwA=; b=XCLZDULw6KH60sdzUwZ2ZaWrnfkoZPWEj896Xpj19xTsTA2V1TsrDJwW4J9WPMcSqL SbJ42ER7IJ9V9sgLevDYzg+CSte4GhhMferR8wKbjUhpQLZjKxYtrAgdUfxQVgQlORBw 1tgJAEa346dq1o+u0KmgLwCd1rCco3R5UyIfs2aeRZ52vn1C1XQ9LWzOazL/1e6C3tOH mugwsGkPLpGevAXdSfbNe3+SJ4ZkkMvG1UjXTtaHc/4icoRUZE9ErzEzc6K0zTBMe2vH aFvRVqNPioCFWzbyS6Np+FrvbM8Qb0jeYBhVRc86YwkCfsBq8mNo02YxBDPnBv6emU0R RUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oxPZ4Dvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020aa7c0d6000000b00457463dfc74si17372491edp.83.2022.10.21.07.49.54; Fri, 21 Oct 2022 07:50:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oxPZ4Dvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbiJUOfo (ORCPT + 99 others); Fri, 21 Oct 2022 10:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJUOfi (ORCPT ); Fri, 21 Oct 2022 10:35:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB26FE22C7 for ; Fri, 21 Oct 2022 07:35:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EA5C961ED9 for ; Fri, 21 Oct 2022 14:35:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E9A8C433B5 for ; Fri, 21 Oct 2022 14:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666362936; bh=B/5S/o4drVYHhiJToyAIzlZIavyyZUO2GzzMWPOCRFM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oxPZ4DvnpzhyB31VWjvWVlmDbdfsz7IIn4MjSXnnZkd7Wxv+JfyO84t1oF/wj4ZIo ADbbMVe1KEckFXK5LhCRuBHiPx3J48pA0p8GaTXKBzlyq5Ka9lr4oLhB94rzAp0jLD w9bMMwkq3j2wrgM8C7AyMOmXS7yg2Jh2bhvWIy6ypy0SilnR+kw1uqnG1wN42e+Kle ICcYjE+wwdh/S5rZ1ZoF8ZnmtXSIVKvJreBDyqndreet6C8RnXCIBNTWse/hdUY5YM zJdKltagoMM6zxGzsjALam5sIG0BqB7OtkaXgslBO0aQMhUZpAkPveERrE3aGNjnIh Srn4b+CQ5dTuA== Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-131dda37dddso3840903fac.0 for ; Fri, 21 Oct 2022 07:35:36 -0700 (PDT) X-Gm-Message-State: ACrzQf2TB+ZpLqvFnO5VPIAHJSGbtIM7eXBnJFjJfyfdD86CbDYNsTpK H1wMLbKnAupZplDHm6OFYv69Z+y0rpPyspLhgys= X-Received: by 2002:a05:6870:5803:b0:12c:c3e0:99dc with SMTP id r3-20020a056870580300b0012cc3e099dcmr27899577oap.19.1666362935455; Fri, 21 Oct 2022 07:35:35 -0700 (PDT) MIME-Version: 1.0 References: <20221019154727.2395-1-jszhang@kernel.org> In-Reply-To: From: Guo Ren Date: Fri, 21 Oct 2022 22:35:23 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] riscv: fix race when vmap stack overflow To: Andrea Parri Cc: Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 21, 2022 at 4:36 PM Andrea Parri wrote: > > > > > + atomic_set_release(&spin_shadow_stack, 0); > > > > > > Have not really looked the details: should there be a matching acquire? > > > > I use atomic_set_release here, because I need earlier memory > > operations finished to make sure the sp is ready then set the spin > > flag. > > > > The following memory operations order is not important, because we > > just care about sp value. > > > > Also, we use relax amoswap before, because sp has naturelly > > dependency. But giving them RCsc is okay here, because we don't care > > about performance here. > > Thanks for the clarification. > > I'm not really suggesting to add unneeded synchronization, even more > so in local/private constructs as in this case. It just felt odd to > see the release without a pairing acquire, so I asked. ;-) Okay, let's keep: handle_kernel_stack_overflow: +1: la sp, spin_shadow_stack + amoswap.w sp, sp, (sp) + bnez sp, 1b + .... + smp_store_release(&spin_shadow_stack, 0); > > Thanks, > Andrea > > > > eg: > > handle_kernel_stack_overflow: > > +1: la sp, spin_shadow_stack > > + amoswap.w.aqrl sp, sp, (sp) > > + bnez sp, 1b > > + > > .... > > + smp_store_release(&spin_shadow_stack, 0); > > + smp_mb(); -- Best Regards Guo Ren