public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	DJ Delorie <dj@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 2/3] Add system-wide tunables: cache ld.so.cache
Date: Thu, 20 Jun 2024 15:08:16 -0400	[thread overview]
Message-ID: <4ee827a9-3f9f-4200-97cc-bc72cdaa7e46@redhat.com> (raw)
In-Reply-To: <d6eb82fb-a044-4dcc-9d22-ad90d6a92377@linaro.org>

On 6/19/24 8:52 AM, Adhemerval Zanella Netto wrote:
> 
> 
> On 29/05/24 14:15, DJ Delorie wrote:
>> Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> writes:
>>> It is not clear to me why we need the load/reload support for ld.so.cache
>>> to support system-wide tunables.
>>
>> It's kinda independent.  Carlos requested it to benefit long-running
>> processes that call dlopen() regularly, to get updates to search paths.
>> The tunables code takes advantage of the refactoring to make sure the
>> cache is loaded when needed, since tunables happens before DSOs.
> 
> But currently we do not catch ld.so.cache, it is mmap'ed on process start
> and unmmap'ed at the end of DT_NEEDED process (elf/rtld.c:2402).  The same
> process is done on dlopen (elf/dl-open.c:909), so any update done by ldconfig
> will be seem on any subsequent dlopen.
The cache, while continuously mapped, is only updated by ldconfig with a rename:

 733   /* Move temporary to its final location.  */
 734   if (rename (temp_name, cache_name))
 735     error (EXIT_FAILURE, errno, _("Renaming of %s to %s failed"), temp_name,
 736            cache_name);

Therefore the old file remains, unlinked from the filesystem, and backing the mapping.

An atomic rename is the only sensible thing to do in this case, we have no guarantee that any
process on the system is in any state to traverse the file mapping while it is being updated.

> There is still a small window where either a new process is starting of dlopen
> is accessing the ld.so.cache contents and ldconfig is doing the final rename 
> of a new cache, but trying to synchronize it would require a more complex
> way (most likely either by making the ld.so.cache private or mapping is a
> shared memory and doing some synchronization).
 
May you please explain the race in more detail?

In summary: We need to detect the file change and reload the cache.

-- 
Cheers,
Carlos.


  reply	other threads:[~2024-06-20 19:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19  3:49 DJ Delorie
2024-05-29 13:16 ` Adhemerval Zanella Netto
2024-05-29 17:15   ` DJ Delorie
2024-06-19 12:52     ` Adhemerval Zanella Netto
2024-06-20 19:08       ` Carlos O'Donell [this message]
2024-06-20 20:37         ` Adhemerval Zanella Netto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ee827a9-3f9f-4200-97cc-bc72cdaa7e46@redhat.com \
    --to=carlos@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).