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 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73165C433F5 for ; Thu, 28 Apr 2022 09:15:38 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nk0FL-0000Ed-Tt; Thu, 28 Apr 2022 05:15:35 -0400 Received: from mxout.security-mail.net ([85.31.212.46] helo=fx303.security-mail.net) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nk0FI-0000EP-Kv for kernelnewbies@kernelnewbies.org; Thu, 28 Apr 2022 05:15:32 -0400 Received: from localhost (localhost [127.0.0.1]) by fx303.security-mail.net (Postfix) with ESMTP id 45A6B3236A1 for ; Thu, 28 Apr 2022 11:15:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kalrayinc.com; s=sec-sig-email; t=1651137331; bh=2/wCHsVEgnXEA95Ha8d464lq/3u6raCad64E1ap+qpE=; h=Date:From:To:Subject; b=hysHaP4TFJRDBNalfDGTVg3oOItmrwIBEJqw/ae6Wr/FfyJ0RF7N2VUkb5lG2XxEC GND+fQMNgX6xa0m6Lpv8riYpdaVx/aIdy6vchgAoiXkUmhEI06Ok1W70LZKGA1D6PE Q+NlozPm5dbbBH4XE18iyH6vcWbiO94/bK8vSqBc= Received: from fx303 (localhost [127.0.0.1]) by fx303.security-mail.net (Postfix) with ESMTP id B429A3235A0 for ; Thu, 28 Apr 2022 11:15:30 +0200 (CEST) Received: from zimbra2.kalray.eu (unknown [217.181.231.53]) by fx303.security-mail.net (Postfix) with ESMTPS id F0DB23236DF for ; Thu, 28 Apr 2022 11:15:27 +0200 (CEST) Received: from zimbra2.kalray.eu (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTPS id D566327E0444 for ; Thu, 28 Apr 2022 11:15:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id BE81627E0448 for ; Thu, 28 Apr 2022 11:15:27 +0200 (CEST) Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jW0140s8fLA3 for ; Thu, 28 Apr 2022 11:15:27 +0200 (CEST) Received: from zimbra2.kalray.eu (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id ADC7427E0444 for ; Thu, 28 Apr 2022 11:15:27 +0200 (CEST) X-Virus-Scanned: E-securemail, by Secumail Secumail-id: <12d65.626a5b2f.ef01a.0> DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra2.kalray.eu BE81627E0448 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalrayinc.com; s=4F334102-7B72-11EB-A74E-42D0B9747555; t=1651137327; bh=dQhpiDF639h3iKZyz7UcfFP8A9mtkoBu0DqOwOhiv+c=; h=Date:From:To:Message-ID:MIME-Version; b=3AlBXtkDXwKHv7gIYCbzgJb0+F+BzoLCJo3AWJbsL/oqUx2zspskJH2PTnCUOiM2W DLz/cb+yJlsfuKSbqbmT3hZrM+0VRU5GaBu6/K+D8gt+tLSdrYELcOhet2Lxs6aPD4 Qo2DvgFlYxIReJbuQzbPB9Mhjzx2zbybfh21Z+xAM70rpsBfAmQ7egjAXpnk5MAuIc XRvAY9nKZtHOQHqPSDIRay1k4aBWHq/5fwsZBpSIXJ4O4Xv2X93NwNqEgU4S1Va5iN XcY67xqmmHNbIwm517oWgCS6Gr013llPO/VgAMBiZ/TqpXQMdhO7yOGrcssMFER561 rrJ8TUMOYcaRw== Date: Thu, 28 Apr 2022 11:15:27 +0200 (CEST) From: Vincent Ray To: kernelnewbies Message-ID: <1168824437.12549419.1651137327677.JavaMail.zimbra@kalray.eu> Subject: smp_processor_id used in preemptable context ? MIME-Version: 1.0 X-Originating-IP: [192.168.40.202] X-Mailer: Zimbra 9.0.0_GA_4126 (ZimbraWebClient - FF99 (Linux)/9.0.0_GA_4126) Thread-Index: O20MIS1yC4b0rYV3DcDXVbyza7b87w== Thread-Topic: smp_processor_id used in preemptable context ? X-ALTERMIMEV2_out: done X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============5603937267727179088==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This message is in MIME format. --===============5603937267727179088== Content-Type: multipart/alternative; boundary=secu_2b8ed4db1aecf3cfa4790d995e78c2ae_part1 This message is in MIME format. --secu_2b8ed4db1aecf3cfa4790d995e78c2ae_part1 Content-Type: text/plain; charset=utf-8 Hi Linux hackers ! I'm reading some code in net/core/dev.c and something puzzles me : somewhere in __dev_queue_xmit, we have : int cpu = smp_processor_id(); /* ok because BHs are off */ and, indeed, a few lines up there is : /* Disable soft irqs for various locks below. Also * stops preemption for RCU. */ rcu_read_lock_bh(); Now I'm wondering : is this really ok ? >From what I understand, this code can very well run in user context, with hard IRQs ON, and in fact it should, according to the following comment : * When calling this method, interrupts MUST be enabled. This is because * the BH enable code must have IRQs enabled so that it will not deadlock. * --BLG Then I guess it could be preempted at any time, especially with aggressive versions of preemptions ? And if so, are we not at risk that our thread is migrated to an other CPU just after smp_processor_id returned ? Cheers, V Ray --secu_2b8ed4db1aecf3cfa4790d995e78c2ae_part1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi Linux hackers !

I'm reading some code in net/core/dev.c and something= puzzles me : somewhere in __dev_queue_xmit, we have :
   &nbs= p;    int cpu =3D smp_processor_id(); /* ok because BHs are = off */

and, indeed, a few lines up there is :
    = /* Disable soft irqs for various locks below. Also
     *= stops preemption for RCU.
     */
    = rcu_read_lock_bh();

Now I'm wondering : is this really ok ?
From = what I understand, this code can very well run in user context, with hard I= RQs ON, and in fact it should, according to the following comment :

=  *      When calling this method, interrupts = MUST be enabled.  This is because
 *    &n= bsp; the BH enable code must have IRQs enabled so that it will not deadlock= .
 *          --BLG
Then I guess it could be preempted at any time, especially with aggres= sive versions of preemptions ?
And if so, are we not at risk that our th= read is migrated to an other CPU just after smp_processor_id returned ?
=
Cheers,

V Ray


= --secu_2b8ed4db1aecf3cfa4790d995e78c2ae_part1-- --===============5603937267727179088== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============5603937267727179088==--