From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB7CEC433EF for ; Thu, 16 Sep 2021 00:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91938610A6 for ; Thu, 16 Sep 2021 00:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233291AbhIPAmT convert rfc822-to-8bit (ORCPT ); Wed, 15 Sep 2021 20:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233237AbhIPAmT (ORCPT ); Wed, 15 Sep 2021 20:42:19 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C3CC061574 for ; Wed, 15 Sep 2021 17:40:59 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4H8ytd6T7YzQjym; Thu, 16 Sep 2021 02:40:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Mime-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=UTF-8 Cc: "linuxppc-dev" , Subject: Re: [PATCH v6 4/4] powerpc/64s: Initialize and use a temporary mm for patching on Radix From: "Christopher M. Riedl" To: "Jordan Niethe" Date: Wed, 15 Sep 2021 19:45:24 -0500 Message-Id: In-Reply-To: X-Rspamd-Queue-Id: 0FFAF1813 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Tue Sep 14, 2021 at 11:24 PM CDT, Jordan Niethe wrote: > On Sat, Sep 11, 2021 at 12:39 PM Christopher M. Riedl > wrote: > > ... > > +/* > > + * This can be called for kernel text or a module. > > + */ > > +static int map_patch_mm(const void *addr, struct patch_mapping *patch_mapping) > > +{ > > + struct page *page; > > + struct mm_struct *patching_mm = __this_cpu_read(cpu_patching_mm); > > + unsigned long patching_addr = __this_cpu_read(cpu_patching_addr); > > + > > + if (is_vmalloc_or_module_addr(addr)) > > + page = vmalloc_to_page(addr); > > + else > > + page = virt_to_page(addr); > > + > > + patch_mapping->ptep = get_locked_pte(patching_mm, patching_addr, > > + &patch_mapping->ptl); > > + if (unlikely(!patch_mapping->ptep)) { > > + pr_warn("map patch: failed to allocate pte for patching\n"); > > + return -1; > > + } > > + > > + set_pte_at(patching_mm, patching_addr, patch_mapping->ptep, > > + pte_mkdirty(mk_pte(page, PAGE_KERNEL))); > > I think because switch_mm_irqs_off() will not necessarily have a > barrier so a ptesync would be needed. > A spurious fault here from __patch_instruction() would not be handled > correctly. Sorry I don't quite follow - can you explain this to me in a bit more detail? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E897C433EF for ; Thu, 16 Sep 2021 00:41:27 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B6E3610A4 for ; Thu, 16 Sep 2021 00:41:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9B6E3610A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bluescreens.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4H8yv92QK6z305M for ; Thu, 16 Sep 2021 10:41:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bluescreens.de (client-ip=2001:67c:2050::465:102; helo=mout-p-102.mailbox.org; envelope-from=cmr@bluescreens.de; receiver=) Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4H8ytk078Zz2yJP for ; Thu, 16 Sep 2021 10:41:01 +1000 (AEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4H8ytd6T7YzQjym; Thu, 16 Sep 2021 02:40:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Subject: Re: [PATCH v6 4/4] powerpc/64s: Initialize and use a temporary mm for patching on Radix From: "Christopher M. Riedl" To: "Jordan Niethe" Date: Wed, 15 Sep 2021 19:45:24 -0500 Message-Id: In-Reply-To: X-Rspamd-Queue-Id: 0FFAF1813 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev , linux-hardening@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue Sep 14, 2021 at 11:24 PM CDT, Jordan Niethe wrote: > On Sat, Sep 11, 2021 at 12:39 PM Christopher M. Riedl > wrote: > > ...=20 > > +/* > > + * This can be called for kernel text or a module. > > + */ > > +static int map_patch_mm(const void *addr, struct patch_mapping *patch_= mapping) > > +{ > > + struct page *page; > > + struct mm_struct *patching_mm =3D __this_cpu_read(cpu_patching_= mm); > > + unsigned long patching_addr =3D __this_cpu_read(cpu_patching_ad= dr); > > + > > + if (is_vmalloc_or_module_addr(addr)) > > + page =3D vmalloc_to_page(addr); > > + else > > + page =3D virt_to_page(addr); > > + > > + patch_mapping->ptep =3D get_locked_pte(patching_mm, patching_ad= dr, > > + &patch_mapping->ptl); > > + if (unlikely(!patch_mapping->ptep)) { > > + pr_warn("map patch: failed to allocate pte for patching= \n"); > > + return -1; > > + } > > + > > + set_pte_at(patching_mm, patching_addr, patch_mapping->ptep, > > + pte_mkdirty(mk_pte(page, PAGE_KERNEL))); > > I think because switch_mm_irqs_off() will not necessarily have a > barrier so a ptesync would be needed. > A spurious fault here from __patch_instruction() would not be handled > correctly. Sorry I don't quite follow - can you explain this to me in a bit more detail?